Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Assigning a reference  RSS feed

 
p sandeep
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

my name sandeep

what is the realtime application and advantage " of assigning a reference directly to a expression " like this:

int height = new Rectangle().height

where rectangle is the class and height is a variable.


Is it right to implement the above one using " this() " so that it can call the present's class constructor
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) You're not assigning a reference.

2) Usually member variables of a class have private access, so your statement won't work.

The fragment new Rectangle() returns a Rectangle object. If you don't assign it to a variable, then after the statement executes, there are no references to the object, so the object is immediately subject to garbage collection, which essentially means you don't use as much memory.

Is it right to implement the above one using " this() " so that it can call the present's class constructor

Perhaps you could rephrase your question because it doesn't make much sense.
[ October 08, 2006: Message edited by: sven studde ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question to more than one forum. See here for an explanation of why I just deleted several other copies of this thread and of your "array length" question.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!