Alexandru Puiu

Ranch Hand
+ Follow
since Feb 22, 2017
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alexandru Puiu

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.
1 month ago
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.
1 month ago
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.   
1 month ago
I've managed to reduce the code. But using reflection, so the question above remains .
1 month ago
Hi guys,
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.

Sorry for the long post.
Thank you in advance!


1 month ago
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!
2 months ago
So the output is:
Boby
Doby
Toby
Boby // why does it call here the constructor from Boby again?
10 30 20

2 months ago
Hi guys!

So I have the following code:


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?

Thanks in advance!
Alex P.
2 months ago
So I have the following code:


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.

Thanks in advance!
2 months ago
Already found the answer! Thank's in advance!
8 months ago
Hi guys,

Can someone please help me understand why do I get an exception here:



My compiler doesn't find anything wrong, but I get the following exception:

8 months ago
So if the exceptions are unchecked it compiles, but if not it does not? 
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? 
 
I'm using Intellij IDEA 2016.2.1 and code with Limp Exception compiles fine... I'm using java 8 that's 100%. 

I've tried to code in a notepad and it doesn't compile... What should I make of this? Is the notepad the office version? And why? Doesn't both use the same JMV?