aspose file tools*
The moose likes Java in General and the fly likes Got good Java eyes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Got good Java eyes?" Watch "Got good Java eyes?" New topic
Author

Got good Java eyes?

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
okay, not a real question, but cool stuff i found in a java book.

the following code compiles without errors:



but why?

oviously it's lame to try it out in your IDE. furthermore it's lame to post the solution in the thread, instead you can post the time you needed...

almost everyone i showed this code needed a couple of minutes, even our senior java architects. guess our brain is kind of biased...

:-)

enjoy,
jan
Ritesh Agrawal
Ranch Hand

Joined: Jan 08, 2004
Posts: 74
Hi,

Nice and smart stuff..took me about 90 secs to find out the trick..

True .. our minds are biased..

Cheers!!


Ritesh<br /> <br />SCJP 1.4<br />IBM Test 340<br />IBM AIX V4.0 Certified Professional<br /> <br />Right actions for the future are the best apologies for wrong ones in the past.<br />- Tyron Edwards
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Wow very nice ..
Took 3 minutes ( approx ) to figure out ..
[ November 08, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Jan]: cool stuff i found in a java book.

Credit where it's due: I believe the book referred to here is Java Puzzlers by Joshua Bloch and Neal Gafter. Highly recommended. Sadly the authors did not actually use the Big Moose Saloon URL in their example, instead choosing to reference their current employer. But we can't have everything I suppose.


"I'm not back." - Bill Harding, Twister
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
actually i found it in a german java book "java ist auch eine insel" ("java is an island, too")...

:-)
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Originally posted by Jan Groth:
actually i found it in a german java book "java ist auch eine insel" ("java is an island, too")...

:-)


Yeah, Germans are good at combining several tens of words while writing German and then splitting them apart in their mind while reading.



English-speakers don't do that for a full-time job.



ASCII silly question, Get a silly ANSI.
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

ooviously it's lame to try it out in your IDE. furthermore it's lame to post the solution in the thread, instead you can post the time you needed...

About 15 seconds. It may be a bit easier for those who spend a lot of time dinking around in the SCJP forum, where the discussion revolves around esoteric constructs like this.

Nice puzzle!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Nice. I passed it around and somebody else got it in a minute or so.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
ritu singhal
Greenhorn

Joined: Nov 03, 2003
Posts: 4
COuld u please explain why it worked ??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

COuld u please explain why it worked ??


Don't scroll down if you don't want to know the answer quite yet....























































It's a label followed by a comment.

[ November 08, 2005: Message edited by: Bear Bibeault ]
[ November 08, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
The question existed well before Java Puzzlers did.
http://jqa.tmorris.net/GetQAndA.action?qids=78&showAnswers=true


Tony Morris
Java Q&A (FAQ, Trivia)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

OK, here's a question for the old-timers:

I could swear that at one time, only loops could be labeled in Java. Was this ever true, proposed to be true, reputed to be true, true of a certain implementation, or otherwise non-false in any situation?


[Jess in Action][AskingGoodQuestions]
Archies Gomes
Ranch Hand

Joined: Jun 19, 2005
Posts: 34
Hi
A nice one infact....Didnt strike at the first glance but when u said its lame to send the solution ...got that in nearly 15 secs...
Good one,
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
>I could swear that at one time, only loops could be labeled in Java.

Any statement can be labelled.

You can use break with any label
You can only use continue with a label on a loop statement.
That may be where the confusion comes from.

There is an example here:
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.15
Akshay Kiran
Ranch Hand

Joined: Aug 18, 2005
Posts: 220
Originally posted by Stefan Evans:
>I could swear that at one time, only loops could be labeled in Java.

Any statement can be labelled.

You can use break with any label
You can only use continue with a label on a loop statement.
That may be where the confusion comes from.

There is an example here:
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.15


"at one time"

nice tricky thing, and it kinda shames me (SCJP 1.5) couldn't get the answer that easy cheers anyway
( there's always a beginning )


"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
 
Don't get me started about those stupid light bulbs.
 
subject: Got good Java eyes?