Is there a way to access a specific Field
on a class without using reflection?
Consider this class:
class MyType {
public int theNumber;
}
Where I would like to get access to theNumber
's java.lang.reflect.Field
.
This works for sure:
Field f = MyType.class.getDeclaredField("theNumber");
However, I would like compile check on the field name, so ideally something like this instead (but of course my example doesn't compile):
Field f = MyType.class::theNumber;
Is this possible or am I way of wrt the compiler abilities?
Aucun commentaire:
Enregistrer un commentaire