suppose I have a two methods defined in on class as following
public void m(final Serializable s){
System.out.println("method 1");
}
public void m(final String s){
System.out.println("method 2");
}
if I have a variable defined as
final Serializable s = "hello world";
How can I use this variable to invoke m so that "method 2" will be printed on the console? I have tried
m(s.getClass().cast(s));
but still method 1 is invoked, but the above code does cast s to String type from my observation.