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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -