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 setting a variable in constructor in 90+ classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting a variable in constructor in 90+ classes" Watch "setting a variable in constructor in 90+ classes" New topic
Author

setting a variable in constructor in 90+ classes

Amaru Shakur
Ranch Hand

Joined: Jul 17, 2008
Posts: 50
ok so i have 90 plus classes where i want to set a variable int id=-1, in every constructor. there has to be a smarter way to do this than by hand. any ideas?


Even though im marked for death I will spark till i loose my breath
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Take five times the amount of time it'd take to do it by hand to write a program to do it for you?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Weinberg
Greenhorn

Joined: Nov 11, 2004
Posts: 18
As Bear mentioned, writing a program to automate this is probably the way to go.

That said, this situation smells a little like a design issue. Is this behavior that all classes share? If so, should it be pulled up into a super or extracted out into it's own class/interface?

Also, aren't you going by Machiavelli now?
[ July 21, 2008: Message edited by: Eric Weinberg ]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Also, aren't you going by Machiavelli now?


I was just about to mention that the moderators might not be aware that this is obviously a ficticiuos name


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Originally posted by Eric Weinberg:
As Bear mentioned, writing a program to automate this is probably the way to go.
Actually, I was advocating nothing of the kind. Guess the sarcasm was lost.

The real question is: why? As Eric pointed out, red flags are waving!
[ July 21, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Originally posted by Garrett Rowe:
I was just about to mention that the moderators might not be aware that this is obviously a ficticiuos name

We are.

"Tupac Amaru Shakur", please check your private messages for an important administrative matter.
Eric Weinberg
Greenhorn

Joined: Nov 11, 2004
Posts: 18

Actually, I was advocating nothing of the kind. Guess the sarcasm was lost.


Ha, my mistake!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting a variable in constructor in 90+ classes