Is my understanding of Java's Class and Type correct? -
in java, when define class, defining type implicitly. say, defined class user
:
class user {}
then class user
, implicit type user
.
when utilize name user
, referencing class user
, type user
. allow me give examples:
user user = new user(); ^^^^(1) ^^^^(2) public void saveuser(user user) { ^^^^(3) } class dao<t> { def save(t t) {} } new dao<user>(); ^^^^(4) class cls = user.class; ^^^^(5) user user = (user) someobj; ^^^^(6)
my understandings:
position(1)
type user
position (2)
constructor of class user
position (3)
type user
position (4)
type user
position (5)
class user
position (6)
type user
is understanding correct?
i say:
class cls = user.class; ^^^^^^^^^^(5) user user = new user(); ^^^^^^^^^^(7)
this type of declaration of variable of type user
this type of definition of variable of type user
(not constructor, constructor may exists subclass of user) this type of declaration of parameter/argument of type user
this generic type user
of definition of generic default constructor of type dao
this referention class of type user
. this cast type user
. this phone call of default-constructor of type/class user
. type or class? every class can type, not every type can class. primitives int
example, type not class. if perfect-scientific-correct, must specify user
class. if user
type, not wrong not specific.
java class types
No comments:
Post a Comment