The way you write code in Spigot is much more different than the way you write code in Sponge. So is there a good guide/tutorial online which covers Java specific to Sponge? Like the way they make use of Java 8 and everything else.
I don’t understand some of the way they use things. I want to learn how things work behind the scenes. Is there any Java specific tutorial for the version Sponge uses?
The Java™ Tutorials is a guide to Java, if that’s what you mean. It is geared towards Java 8
Sponge doesn’t abuse too many java 8 features to my knowledge, it’s just different to what you are used to.
My apology for not explaining it correctly. I will try to be more specific. Interfaces such as Optional, Builder and things like that is something new to me. I want to make my own Builder/Optional class but I need to know how it works. No, I am not talking about Builder Design Pattern, I am talking about the Builder class that the message/chat and command system is made out of. Thanks!
If you mean stuff like SpongeAPI/src/main/java/org/spongepowered/api/text/Text.java at fad3807910b61ab9cf7face5413a15a54f3d0816 · SpongePowered/SpongeAPI · GitHub
it’s just a nested class, and it absolutely follows the builder design pattern. Nested Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the enclosing class. As a member of the OuterClass, a nested class can be declared private, public, protected, or package private. (Recall that outer classes can only be declared public or package private.)
So in this case, as it’s static, it’s just for organizations sake.
Now for Optional, you shouldn’t ever need to make your own, it’s just a design decision to avoid null pointer exceptions when using the API.
I suspect what you want to do however, is return your own types wrapped in an Optional.
Optional uses generics in order to return the correct type, you make have already used them for creating collections of types. You can read more about Optional here: Tired of Null Pointer Exceptions? Consider Using Java SE 8's Optional!
Thanks a lot Ryan! That was pretty dang useful.
Cool, I wasn’t so sure if that was what you needed / was referring to, or if you were trying to work out how to use abstract classes / interfaces with inheritance.
Glad it helped.