Creating a user defined class in java just like Integer/String class

Sarath Subu

I have a very basic doubt. Is it possible to create a class in which objects can be created using '=' operator (just like Integer/String class) rather than using "new CustomClass()".

Consider a class named CustomClass. I need to define my class just a way that it works just like Integer/String class in terms of the syntax for create objects.

Eg. In order to create Integer object we write, Integer pInt = 10 or String pStr = "testWorld"; LikeWise, I want objects of my custom class "CustomClass" to be created using simple syntax like CustomClass custObj = 45;

Kayaman

No, Java doesn't provide a way for that. Even String is a special case in Java, given some extra syntax to make things easier. As for Integer x = 10;, that's just autoboxing although it doesn't require the new syntax either.

You'll have to make do with constructors and factory methods.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating Set of objects of user defined class in python

From Dev

Creating Set of objects of user defined class in python

From Dev

Pentaho Data Integration User Defined Java Class

From Dev

User-defined class objects in Java TreeMap

From Dev

Using setDate for User defined class.. Java

From Dev

How to create user defined immutable class in Java which is having user defined class object as a class member?

From Dev

Why do you have to use .class in Java to get the Class object? Why not just the class name like in Ruby?

From Dev

HTML scraping in PDI spoon step (user defined java class)

From Dev

H2 database User defined java function Class not found

From Dev

How to get Field value in User Defined Java Class in kettle?

From Dev

How to create an ArrayList object in an User Defined Java Class in Kettle?

From Dev

Is there a way to make an array of a user-defined class type in java?

From Dev

JNI: What signature to use when returning a user defined java class?

From Dev

User defined Key Class for HashMap

From Dev

Write a user defined class in laravel?

From Dev

Creating a node class in Java

From Dev

Creating an instance of a class in Java?

From Dev

Java creating a time class

From Dev

Basics to creating a class in java

From Dev

Custom comparator for custom class, just like STL

From Dev

Custom comparator for custom class, just like STL

From Dev

Syntax error: missing ';' before '*' when creating a pointer object of a user defined abstract class

From Dev

Adding class to div user has just scrolled to

From Dev

Creating a Custom IntStream-like class

From Dev

creating class object that normally looks like a float

From Dev

Access class defined in method in Java

From Dev

creating a class like App.xaml.cs in Class Library Project

From Dev

Spring Java Config Error creating bean with name 'entityManagerFactory' defined in class path resource

From Dev

Spring Java Config Error creating bean with name 'entityManagerFactory' defined in class path resource

Related Related

  1. 1

    Creating Set of objects of user defined class in python

  2. 2

    Creating Set of objects of user defined class in python

  3. 3

    Pentaho Data Integration User Defined Java Class

  4. 4

    User-defined class objects in Java TreeMap

  5. 5

    Using setDate for User defined class.. Java

  6. 6

    How to create user defined immutable class in Java which is having user defined class object as a class member?

  7. 7

    Why do you have to use .class in Java to get the Class object? Why not just the class name like in Ruby?

  8. 8

    HTML scraping in PDI spoon step (user defined java class)

  9. 9

    H2 database User defined java function Class not found

  10. 10

    How to get Field value in User Defined Java Class in kettle?

  11. 11

    How to create an ArrayList object in an User Defined Java Class in Kettle?

  12. 12

    Is there a way to make an array of a user-defined class type in java?

  13. 13

    JNI: What signature to use when returning a user defined java class?

  14. 14

    User defined Key Class for HashMap

  15. 15

    Write a user defined class in laravel?

  16. 16

    Creating a node class in Java

  17. 17

    Creating an instance of a class in Java?

  18. 18

    Java creating a time class

  19. 19

    Basics to creating a class in java

  20. 20

    Custom comparator for custom class, just like STL

  21. 21

    Custom comparator for custom class, just like STL

  22. 22

    Syntax error: missing ';' before '*' when creating a pointer object of a user defined abstract class

  23. 23

    Adding class to div user has just scrolled to

  24. 24

    Creating a Custom IntStream-like class

  25. 25

    creating class object that normally looks like a float

  26. 26

    Access class defined in method in Java

  27. 27

    creating a class like App.xaml.cs in Class Library Project

  28. 28

    Spring Java Config Error creating bean with name 'entityManagerFactory' defined in class path resource

  29. 29

    Spring Java Config Error creating bean with name 'entityManagerFactory' defined in class path resource

HotTag

Archive