File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Condense declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Condense declarations" Watch "Condense declarations" New topic
Author

Condense declarations

Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Anyway to condense the declarations below?




I was hoping for something like this but it doesnt work:
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Mike,
The single line version compiles when I try it. What error are you getting?

Note that some people (including myself) find the expanded version clearer.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671

That is legal code, however it only initializes the last variable. You may want this instead:


"I'm not back." - Bill Harding, Twister
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41867
    
  63
Or this:


Ping & DNS - my free Android networking tools app
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
No, I believe that last one is legal in some other languages, but it's not legal in Java.
[ November 16, 2007: Message edited by: Jim Yingst ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41867
    
  63
Oops, you're right of course. Just goes to show how long it's been since I fell out the habit of using these shortened initializations. There is something to be said for making them explicit.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

It isn't; streets, schools and people are not declared in Java this way, so the compiler fails because of three unresolved symbols.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Condense declarations