Well, first the fields must be a string, not an array, because the values are updated with the values entered by the used in a web page. The values are sent to the class as a string. So I would still have to put them into the array, just like I would in the list.
Second, I was aiming on using the Java 8, Steam.API.
I don't know how I can do that. I mean, on the website, the user has to choose the planet type and size. The planet values are in direct correlation with those two. I must have a method somewhere that constructs them. But like I said a number of five "if"'s would have resolved the problem.
This question was more about Streams, and if someone knows a way to use two different lists(in term of the object type that they contain) and with a Stream to combine them 1:1 into another list.
So in the following method, I have an object that has a constructor that takes two other objects as arguments. The solution that I've written works, but I was wondering if you guys know of a more compact solution. With less code.
This class receives the values of it's fields from a webpage. The method puts them in a List, transforms them into Enums, and collects them into 2 lists. Then with the last Stream, it uses the first two lists to create a number of Objects of type Planet.
I was wondering if the 3 Streams can be rewritten into only 1 or 2. The code above is the equivalent of:
It all boils down to if it's recommended to use Streams when you have two different lists, and the objects into those lists must be combine into another one, 1:1. By 1:1, I mean that the object at index 0 in one list will have to be combined with the object at index 0 in the other list. Also the lists will always have the same number of objects.
Thank you for your answers! I've seen it. I was so tired that I forgot about the instantiation at line 29, calling all the constructors! And at line 41 was the call for the first nonserializable parent constructor!
I don't understand why does it print Boby, again, at the end.
So when I'm deserializing the object back, the constructor of the first nonserializable parent class is called. So I get the first "Boby". Then the other objects are constructed back, so I get "Doby" and "Toby". But why does it call the constructor of Boby again, at the end?
My question is why am I allowed to put a String object in the Queue helped, in the method helpPeople, when the Queue given to the method as argument. helpedQ, is a Queue<Person>? I understand why the compiler allows this (it only gives a warning), but shouldn't the code throw an ClassCastException or any other exception? Because in the end I will have a Queue of Person objects, with a String object in it.
Ok, now I'm a little confuse as to why is Exception legal. I mean there is no checked exception that the code can throw that is not already a HurtException, right?
I always though that as long as the exceptions declared in the catch blocks argument are in order from the most specific to the most broad, everything is ok. Like in the example below:
Further more in the book at page 310, there is actually an example about something similar, but the exceptions there are unchecked exceptions. As a general rule: if the exceptions are unchecked it compiles, but if not it does not?