• Post Reply Bookmark Topic Watch Topic
  • New Topic

Garbarge Collection exercise Ch 9 Head First Java  RSS feed

 
Jim Brent
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on the Be the Garbage Collector exercise in Head First Java Chapter 9 page 266 and don't understand the code in line 3 (actually the second line of code)...



I am specifically looking at the line:


I don't get what this is doing...

Supposedly this is creating an method. However, I don't understand the space between "GC" and doStuff()...

Farther down in the code sample the method is referred to as doStuff(), NOT GC doStuff();

--- I found a similar question was posted and answered here: http://www.coderanch.com/t/417054/java/java/Garbage-collection-eligibility

Sorry to post a possible duplicate question, but I have been trying to find any reference to creating methods with a class name <space> method and I don't readily see anything like this.

Thank you for your assistance and patience.

V/r,

Jim







 
sal jefferson
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this book a while ago, I dont remember this but I can answer part of this question.

A recognizable method signature looks something like this

is the return type of this method, meaning it returns no value.

You can have a return type of primitives, or objects as well. For example


So these three methods have a return type of int, String and GC respectively. Where "GC" is some object somewhere.
To call GC collectStuff you would say
As for what this method does? I have no idea But I hope this answers your question, or part of it anyway.

EDIT: If I would have looked a little closer I could have seen that doStruff() calls a second method doStuff2(GC), which takes a GC object as an argument and creates a new GC object.
 
Jim Brent
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course GC is the return type... (GC Object)...

Thank you... Now I get it...
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sal jefferson wrote:. . . As for what this method does? I have no idea . . . second method doStuff2(GC), which takes a GC object as an argument and creates a new GC object.
Have another look at doStuff2. They probably chose those poor names for people who are practising for certification exams because they sometimes have very poor code style in. Now work out not only what doStuff2 does, but also whether it does anything at all
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!