Reputation: 11
How return integer in function String
It's my code
public class Utils {
public static String type(String s){
if(UraniumProtectMain.materialname){
return s;
} else {
return Integer.parseInt(s); //<--- It's
}
}
}
Upvotes: 1
Views: 107
Reputation: 76
As you want to return both Integer and String, you can use return type as Object class, because Object is super class of all classes and we can hold any type of value in Object variable.
public static Object type(String s){
// code here
}
Now you can get the type of value return by type with the help of instanceOf method
if(Utils.type() instaceOf String)
{
// code here
} else if(Utils.type() instanceOf Integer) {
// code here
}
Upvotes: 1