• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does Bruce Eckel says that only objects can be passed into a function?  RSS feed

 
Mark Sanders
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Here's a quote from Bruce Eckel's book "Thinking in Java":
The method argument list specifies what information you pass into the method. As you might guess, this information—like everything else in Java—takes the form of objects. So, what you must specify in the argument list are the types of the objects to pass in and the name to use for each one.


I don't get it. I think you can pass primitives to a method (e.g. int) and primitives aren't objects.

For example:


This is a method and there are only primitives in it, no objects at all.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Perhaps you took the quote out of context? Was he taking about a specific method (with arguments)?

Henry
 
Mark Sanders
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it was an introduction to methods and I'm almost sure he was talking about methods in general. Here's a bigger part of the paragraph but I don' think the rest is very relevant for my question:

The argument list

The method argument list specifies what information you pass into the method. As you might guess, this information—like everything else in Java—takes the form of objects. So, what you must specify in the argument list are the types of the objects to pass in and the name to use for each one. As in any situation in Java where you seem to be handing objects around, you are actually passing references.4 The type of the reference must be correct, however. If the argument is supposed to be a String, you must pass in a String or the compiler will give an error. Consider a method that takes a String as its argument. Here is the definition, which must be placed within a class definition for it to be compiled:
[...]


I still think his words are untrue and I don't see it as out of a context.
If anybody wants to explore it further, it's on page 49 in the printed version of "Thinking in Java" and on page 70 in the digital one.
 
Mark Sanders
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I got it. It turned out to be a little out of context but the context here was the whole chapter which was titled "Everything is an object". Now I know he mentions later that the primitives are a special case. Here's the link to this question on Stack Overflow in case it bugs somebody else.
http://stackoverflow.com/questions/29315957/why-does-bruce-eckel-says-that-only-objects-can-be-passed-into-a-method-in-java
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out and welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!