File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Got good Java eyes?

 
Jan Groth
Ranch Hand
Posts: 456
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

True .. our minds are biased..

Cheers!!
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow very nice ..
Took 3 minutes ( approx ) to figure out ..
[ November 08, 2005: Message edited by: Srinivasa Raghavan ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
Jan Groth
Ranch Hand
Posts: 456
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i found it in a german java book "java ist auch eine insel" ("java is an island, too")...

:-)
 
Stuart Ash
Ranch Hand
Posts: 637
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice. I passed it around and somebody else got it in a minute or so.
 
ritu singhal
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
COuld u please explain why it worked ??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question existed well before Java Puzzlers did.
http://jqa.tmorris.net/GetQAndA.action?qids=78&showAnswers=true
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Archies Gomes
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
Posts: 220
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic