May create a new primitive data type in Java

The first thing I want to clarify here is this question is caused by curiosity. I am not facing any problem.

In Java, byte , short , int , etc. there are many primitive types, etc. Now suppose I want to create a new primitive type (like mediumint or something else). Can we do this? If so, how?

+7
source share
5 answers

Primitive types are those that are defined by the language itself. In Java you can only define new types as Classes all derived from the common base class Object .

+8
source

You could, but then it will no longer be Java.

+4
source

You cannot create your own primitive data type.

As explained in the Java documentation: The primitive type is predefined by the language and named by the reserved keyword.

+1
source

Just No, you cannot create a primitive data type.

Primitive data types that are provided and exist in a language function. Basically, Java supports this for performance reasons and does arithmetic work.

You can create a user-defined data type using the concept of class and object .

+1
source

You are all mistaken. Yes. You can. As a rule, you do not need a completely new primitive type. Thus, you do not need to restore the JVM. Usually you only need to "package" or "distinguish" your new primitive type to the existing one and define some operations, such as "+" with its shell.

You can do this relatively simply with the original JVM, but with your own Java compiler. Good luck

0
source

All Articles