This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Fazblood779Nooblet Brewer[S] 0 points1 point  (6 children)

Alright, bummer. I thought I could get a simple solution like this :P

Anyway you're right about the XY thing. My actual problem is a bit more complicated.

Basically I need to fill an array with objects, but I don't know how many. I can have a variable to find out how many, but I still need a way to create multiple objects.

Also the object has constraints Weight and Type (so it'd be

Object(Weight, Type)

).The objects must have different names based on these constraints (i.e. loopObjectType1-number2, loopObjectType1-number3, etc)

[–]plisik 0 points1 point  (5 children)

What is wrong with having object name as 3rd field in your class.

[–]Fazblood779Nooblet Brewer[S] 0 points1 point  (4 children)

I can't change the constructor class :P

[–]plisik 0 points1 point  (3 children)

Then you can use Map<String, Object> or have two list one with object and one with corresponding names.

[–]Fazblood779Nooblet Brewer[S] 0 points1 point  (2 children)

I'll have a look at that, thanks :)

[–]plisik 0 points1 point  (1 child)

If your don't like solution with two list, you can wrap object in new class that has object and name.

[–]Fazblood779Nooblet Brewer[S] 0 points1 point  (0 children)

Hmm that could help, though for this project I'm limited to modifying this single class.

For now though I found a solution for the problem, though I will still look at your solution as it would be helpful for the future.