d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > How To Apply A Prefix To Each Part Of A Block
Add Reply New Topic New Poll
Member
Posts: 13,356
Joined: Jul 9 2011
Gold: 1,700.43
Nov 17 2015 05:45pm
Alright, I'm relatively new to Java, and looking for help making writing lengthy code faster.

I need to initialize a few hundred objects with different parameters in my main method, and no, they can't be made with a loop, they're irregular.

Is there a way to do something like

addPrefix"xxLongStupidNameHerexx.addobject.{
new thing(a,b,c);
new thing(p,l,o);
new thing(p,l,o);
}

and have the compiler read the code as
xxLongStupidNameHerexx.addobject(new thing(a,b,c));
xxLongStupidNameHerexx.addobject(new thing(a,c,x));
xxLongStupidNameHerexx.addobject(new thing(p,l,o));


Basically I want to avoid writing the same starting bit for a lot of code that can't be made with a loop. I know I've seen this done before in other people's work, but I can't find it on bae stackoverflow or google.
Member
Posts: 21,211
Joined: May 22 2009
Gold: 9,036.90
Nov 17 2015 07:34pm
xxLongStupidNameHerexx
This is called a varying variable and no you can't do this and you shouldn't be able to do this for security concerns.
LongStupidNameHere
This also sums up the disgusting Java conventions but anyway...

You need to find a way to do this in a loop

This post was edited by zeroRooter on Nov 17 2015 07:35pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 17 2015 08:07pm
void superShortOneLetterFunctionNameThatsReallyEasyToTypeButMakesNoSense(int param1, int param2, int param3){
xxLongStupidNameHerexx.addobject(new thing(param1,param2,param3));
}

z(a, b, c);
z(p, l, o);
z(a, c, x);

/edit alternatively, provide an import feature. specify your data in csv then you can loop through it and do your magic.

/edit2: alternatively, you can add shortcuts in your IDE. kind like how syso expands to System.out.println in eclipse

This post was edited by carteblanche on Nov 17 2015 08:08pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll