Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Get object of class depending on its name
    primarykey
    data
    text
    <p>this is my situation:</p> <p>I have a method which has a String as parameter. This method has to receive an object from a class called Urls. The object it has to recieve, has the same name as the value of the String. Here is my code:</p> <pre><code>private Object getObject(String objectName){ try { Field field = Urls.class.getField(objectName); } catch (NoSuchFieldException e) {} catch (IllegalAccessException e) {} } </code></pre> <p>And here is my Urls class:</p> <pre><code>public class Urls{ public static final String[] ASTUN = new String[]{ "http://www.astun.com/camara/truchas.jpg", "https://www.todonieve.com/photowebcam.asp?fotografia=astun/astun.jpg", "http://www.astun.com/camara/caba%C3%B1a%20sarrios.jpg", "http://www.astun.com/camara/sector%20sarrios.jpg", "http://www.astun.com/camara/sector%20raca%20prad.jpg", "http://www.astun.com/camara/sector%20aguila%20cr.jpg", "http://www.astun.com/camara/sector%20truchas.jpg", "http://www.astun.com/camara/sector%20llanos%20.jpg", "http://www.astun.com/camara/llegada.jpg", "http://www.astun.com/camara/terraza.jpg", "http://www.astun.com/camara/panoramica.jpg", "http://www.astun.com/camara/snow.jpg" }; private static final String[] CANDANCHU = new String[]{ "https://www.todonieve.com/photowebcam.asp?fotografia=candanchu/candanchu.jpg", "https://www.todonieve.com/photowebcam.asp?fotografia=CandanchuNew/CandanchuNew.jpg", "https://www.todonieve.com/photowebcam.asp?fotografia=candanchu_rinconada/candanchu_rinco.jpg", "https://www.todonieve.com/photowebcam.asp?fotografia=candanchu_tobazo/candanchu_tobazo.jpg" }; } </code></pre> <p>So, that way I have a Field object, but how can I get the String[] of that field? I have read about the get(Object object) method of Field class but it seems that i doesnt do what I want to do...</p> <p>EDIT: I WANT TO GET ASTUN OR CANDACHU STRING ARRAYS</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload