I am new to Java reflection. I am trying to make a program where addition of two numbers gives custom result. Below is the code:
public class MoreTest {
public static void main(String[] args) {
try {
Field field = Integer.class.getDeclaredField( "value" );
field.setAccessible( true );
field.setInt(Integer.valueOf(2),2);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
Integer a = 2;
Integer b = 4;
System.out.println( a + b ); // should print 8
}
}
What I can do in the above code to print the output I need?
Aucun commentaire:
Enregistrer un commentaire