Isn't kotlin a better option?
post
So, it's C#'s Nullavle Reference Types feature" but for Java, and not baked into the language.
Interesting. But can't you do basically the same thing with @nonnull annotations? I remember using something like that a decade ago when I last wrote Java.
Notably, there is currently no ‘superset’ language that keeps Java syntax almost intact
There's Groovy. Their examples use a bit different syntax, like a lack of semicolons, and Gradle might also give the wrong idea. But it's fully compatible with Java source code iirc, just adds its own stuff on top and broadens the allowed syntax a bit.
There is one Groovy syntax that replaces some Java syntax: code blocks now become closures.
What you can write in Java as
{
System.out.println("Hello, world!");
}
You would have to write in Groovy with a label
l: {
System.out.println("Hello, world!");
}
There’s Groovy. Their examples use a bit different syntax, like a lack of semicolons, and Gradle might also give the wrong idea. But it’s fully compatible with Java source code iirc, just adds its own stuff on top and broadens the allowed syntax a bit.
Groovy is highly compatible with Java and most Java code runs in Groovy without changes. However, it’s not 100% identical. Groovy introduces dynamic typing, additional syntax, and runtime behaviors that can differ from Java. JPlus, on the other hand, aims to keep Java syntax almost intact while adding null-safety and boilerplate code generation making it easier to apply to existing Java projects without rewriting code
You say:
Groovy is not 100% identical
Then you say:
JPlus aims to keep Java syntax almost intact
Which implies that it is not 100% identical either.
So why do you apply that same argument against one but not the other? Seems like marketing bs.
You say:
Groovy is not 100% identical
Then you say:
JPlus aims to keep Java syntax almost intact
Which implies that it is not 100% identical either.
So why do you apply that same argument against one but not the other? Seems like marketing bs.
As you mentioned, the phrasing might make it seem inconsistent. The key difference here is not whether they are “100% identical,” but the degree and nature of the changes.
Groovy introduces dynamic typing, optional syntax, runtime behaviors, and other language features that can fundamentally alter how Java code executes. Even if the code compiles, subtle differences in behavior can occur. In contrast, JPlus preserves nearly all standard Java syntax while only adding compile-time null-safety checks and boilerplate code generation. These changes have minimal impact on the execution of existing Java code and are primarily intended to improve safety and developer convenience.
Additionally, JPlus is currently developed based on Java 20 syntax, with added null-safety and boilerplate code generation features. Therefore, code up to Java 20 is fully compatible. Since future updates will support the latest Java syntax as well, the phrasing “almost identical” is used intentionally. In practice, JPlus will continue to be Java syntax + α.
Technically, neither language is “100% identical” to Java, but the practical impact is very different. Groovy can alter runtime behavior, whereas JPlus preserves existing behavior almost entirely while adding safety and developer convenience. This is not marketing exaggeration, but a reflection of the difference in the invasiveness of changes.
Things can get confusing if the explanation is too long, so here’s a concise way to put it.
It’s not entirely clear whether Groovy includes 100% of Java syntax, but in my view, Groovy focuses on enhancing the language itself, addressing areas where it falls short compared to modern languages.
On the other hand, JPlus is similar to how TypeScript addresses JavaScript’s lack of type safety: it focuses on strengthening Java’s safety while improving developer convenience through features like boilerplate code generation. Importantly, JPlus code always compiles down to standard Java, which means it can be integrated seamlessly into existing Java projects without changing the build environment or toolchain.
In short:
Groovy: Focuses on enhancing the expressive power of Java, adding modern language features and syntactic flexibility.
JPlus: Focuses on enhancing language safety and developer convenience, while maintaining full compatibility with Java. This allows developers to adopt JPlus without worrying about breaking existing Java projects.
So, it's C#'s Nullavle Reference Types feature" but for Java, and not baked into the language.
So, it's C#'s Nullavle Reference Types feature" but for Java, and not baked into the language.
But there is a reason for null, its a really nice thing you can work with.... I really don't understand all the fuss about null safety, working against the language
Nulls are useful, but you can't work with them in Java. Anything can be null at any time without warning, even when you have absolutely no reason to ever allow a null. Null safety as a language feature gives you the choice to allow nulls when they make sense or guarantee a value when needed. It saves you checking for nulls in the core of your logic when you already ruled them out at the boundary and enforced it at compile time.
If you check for them in your boundary, you shouldn't check for them everywhere, only where you possibly introduce them ...
I want to write functions that fail at compile time if called with a null object. You can use annotations to kinda do this, but they do not produce compile errors.
But you should just throw an exemption, and let the caller handle it. There is so many variations where an object is null, you can't control, or you are deep inside your own code, it should be covered by a test.
The problem is that when an project is too big and a method is called from multiple contexts it's very easy to lose track of the context where the null check has been done and where it hasn't. This leads to a lot of duplicated null checks around the project and the constant paranoia of "can this be null here?".
A much better way of doing this is using the Optional when an Object can be "null" and a direct instance where it cannot. This way, at any given context you know for absolute sure if a null check is needed or not. However, even with annotations this does not throw a compile error...
all 34 comments