java - use different types, or use Object? -
sorry noobish question, why use string, int , others, if can use object type?
i mean use object one; instead of string one;
for example, string class declares bunch of methods. if variable declared object, methods declared in object , super classes (none) visible on variable, regardless of type of actual object.
you can do
string 1 = new string("whatever"); system.out.println(one.length()); but can't do
object 1 = new string("whatever"); system.out.println(one.length()); methods , fields resolved on compile time type of variable.
Comments
Post a Comment