+ 2
Overriding a variable
Can I somehow override a string variable, for example, to int variable? Something like that String a = "5"; if (true) { @Override int a = Integer.valueOf(a); } if (a instanceof Integer) System.out.print(" override done"); --- Basically I need to make clear whether user's input is a string or integer and use it afterwards.
1 Réponse
+ 1
No, this is not a way how overriding works in Java. But you can use Scanner class to parse the input.
Scanner sc = new Scanner(System.in);
if (sc.hasNextInt()) {
doSomething();
} else {
doSomethingElse();
}