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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -