Search code examples
javaobjectprimitive

Why does Bruce Eckel says that only objects can be passed into a method in Java?


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:

public static int multiply(int x, int y){
    return x * y;

This is a method and there are only primitives in it, no objects at all.


Solution

  • The author doesn't say that only objects can be passed to methods. This quote comes in the context of a chapter called "Everything is an Object". It aims to highlight the object-oriented aspect of the language, but it also includes a section on primitives which explains that they are a special case.

    Nevertheless, what you say about the method taking only primitive types is still correct but this is implicitly covered by the "Special case: primitive types" section.