This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question about section of the Oracle Java Tutorials regarding interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about section of the Oracle Java Tutorials regarding interfaces" Watch "Question about section of the Oracle Java Tutorials regarding interfaces" New topic
Author

Question about section of the Oracle Java Tutorials regarding interfaces

simon fletcher
Ranch Hand

Joined: Aug 04, 2012
Posts: 50
The examples on this page of the Oracle Java Tutorials have some examples like

There are two other similar examples and each of them have the line

Why is obj1 in brackets? By the way I don't mean the brackets that relate to the if statement. I mean the ones that directly surround obj1, as in (obj1). Is it just a typo? I don't recall seeing this kind of thing before.

Thanks for taking the time to look at this.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

It's just a way someone is used to write code. In this case there would be no difference if you omit those around obj1. Take a look at this:

Both statements produce same output. It's just a matter of coding style.


The quieter you are, the more you are able to hear.
simon fletcher
Ranch Hand

Joined: Aug 04, 2012
Posts: 50
I guess then it's nothing more than if someone wrote a math statement like (23)*46. The brackets don't do anything. They get ignored by the compiler.

Thankyou.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7503
    
  18

simon fletcher wrote:I guess then it's nothing more than if someone wrote a math statement like (23)*46. The brackets don't do anything. They get ignored by the compiler.

Actually, they don't get ignored; it's just that in this situation, they don't do anything. If you wrote (23+1)*46, they most certainly would.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
 
subject: Question about section of the Oracle Java Tutorials regarding interfaces
 
Similar Threads
Threading conceptual doubt ...
Objects involved in a cycle!
Using interface as a type
Interfaces and the Java Tutorial
jaxb marshall java to xml