I want to check if a provided argument is a reference to a specific static field of a class, but want the method to be able to be passed the static reference directly and derive the Field
property of the argument internally:
/*
* I want:
*
* isCharacterCurrencySymbolReference(Character.CURRENCY_SYMBOL) to evaluate to true
*
* while something like:
*
* isCharacterCurrencySymbolReference(Character.LINE_SEPARATOR) to evaluate to false
*
*/
public static boolean isCharacterCurrencySymbolReference(Byte staticCharacterField)
{
return Character.class.getField("CURRENCY_SYMBOL") == staticCharacterField.getFieldThisArgumentIsReferenceTo();
}
Would something like that be possible or because the static reference is evaluated to a primitive byte at runtime make it impossible without the method just being passed a Field
as an argument directly?
Aucun commentaire:
Enregistrer un commentaire