Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interpret line attempt

 
Mike Jenkins
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand this line that is in a Servlet.
Please tell me if I am correct or wrong on how I interpret the bolded line below.
boolean dataExists = new Baseball().hitBall(String Mays, String McCovey);

The line creates a boolean datatype called dataExists which is a object reference that is assigned to a new Baseball type object where it is calling Baseball no argument constructor AND it is calling a (non static) boolean two parameter method called hitBall? For example the Baseball no arg constructor could have some code with the Database connection statement and the boolean method hitBall would have this as its signature method: public boolean hitball(String Mays, String McCovey)
[ April 10, 2007: Message edited by: Mike Jenkins ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not servlet-specific, so moved to a more appropriate forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Close, but as written, the line will yield a compiler error. Type names are not included in method call parameters.

Were the line writen as:



I'd amend your description as follows:

The line creates a boolean variable called dataExists which is a boolean value that is assigned from a call to the hitBall() method of a new instance of Baseball created using a no-args constructor.

An important nuance that your description seemed to miss is that a reference to the newly created Baseball instance is not stored anywhere.
[ April 10, 2007: Message edited by: Bear Bibeault ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Jenkins:
...The line creates a boolean datatype called dataExists which is a object reference that is assigned to a new Baseball type object...

Just to clarify a bit further, boolean with a lowercase 'b' is a primitive type -- not an object. (The boolean wrapper class uses an uppercase 'B'.) So instead of referencing an object, dataExists will only hold a primitive value of true or false.
 
Mike Jenkins
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replies and my apology for originally putting in Servlet Forum.
From both responses:
"An important nuance that your description seemed to miss is that a reference to the newly created Baseball instance is not stored anywhere."
and
"So instead of referencing an object, dataExists will only hold a primitive value"

I assume there is no reference in this: boolean dataExists = .. because the boolean is a primitive data type BUT if it said this: Boolean dataExist = .. then it would be a reference to a Baseball instance (object)?
[ April 10, 2007: Message edited by: Mike Jenkins ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it would be a reference to a Boolean.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Lynn:
No it would be a reference to a Boolean.


Moreover, it would be whatever was returned from the hitBall() method, which would need to be a Boolean for the line to compile.
 
Mike Jenkins
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,


Can I get clarification on this:
"An important nuance that your description seemed to miss is that a reference to the newly created Baseball instance is not stored anywhere."

This means there is no reference variable in the statement so there is nothing to store anywhere?
[ April 10, 2007: Message edited by: Mike Jenkins ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic