Collin Chappell
Collin Chappell

Reputation: 31

Creating your own keywords in java?

I was wondering if this would work. In java, you use 'null' to make something nothing. Would this work?

Object nil = null;

Could I then use nil instead of null? Thanks!

Upvotes: 1

Views: 475

Answers (1)

Karuna
Karuna

Reputation: 739

Java doesn't allow for this.

However, if you want to achieve this sort of syntax whilst being able to run your code on a JVM (and with other Java code), you could look at Groovy, which has operator overloading (and with which you could also use DSLs for short syntax which would have similar effects to using custom operators).

Note that defining custom operators (not just overloading) is a big deal in any language, since you would have to be able to alter the lexer and grammar somehow.

Upvotes: 1

Related Questions