Skip to content

Java tagged union / sum types

Is there any way to define a sum type in Java? Java seems to naturally support product types directly, and I thought enums might allow it to support sum types, and inheritance looks like maybe it could do it, but there is at least one case I can’t resolve. To elaborate, a sum type is a type which can ha…

How to solve the java.nio.file.NoSuchFileException?

I have a file called “result.csv”, from that file i want to read certain data and display them. I have that file in my eclipse project folder itself. Still i’m unable to read the file. OUTPUT: Can anyone point where exactly i missed? and how can i overcome this or any alternate methods for t…

Transform SQL to Hibernate criteria

I am writing a method for retrieving clients with sum of their orders (order.total) higher and less than input values. All its okay, but, sometimes i am get an error: How can i correcting this method, or, maybe, convert this in full criteria style? Answer In the end, i solved this problem by this way, using s…

Creating two objects with same name in Java

I have a class name Planet and I am making objects in main. However, I saw my instructor doing this: So basically, my instructor is also creating two objects. I understand that a new object is basically formed when constructor is called but I always thought that the two objects need to have distinct names as …

What does “class loading deadlock” mean here?

I have this classes: And code inspector is detecting this warning: Referencing subclass NonRegisteredUser from superclass User initializer might lead to class loading deadlock What does it mean exactly? Answer The deadlock can only occur if you have 2 threads and one starts to load User and one starts to load…