In one line, There is nothing in Java which is equivalent to typedef of C++.
In Java, class is used to name and construct types or we can say that class is the combined function of C++’s struct and typedef. But that is totally different thing and not the equivalent of typedef anywhere.
typedef: It is a keyword not a function that is used in C/C++ language to assign alternative names to existing data types. It is used with the user defined data types when the name of data types get little bit complicated that time the typedef keyword is used, unless it is unnecessary.
Syntax of using typedef:
typedef existing_name alias_name;
typedef with pointers:
typedef will also work with the pointer in C/C++ language like renaming existing keywords. In case of pointers * binds in the right not the left side.
int* x, y;
In the above syntax, we are actually declaring x as a pointer of type int, whereas y will be declared as a plain integer But if we use typedef then we can declare any number of pointers in a single statement like below.
typedef int* IntPtr ; IntPtr x, y, z;
typedef can be used for :
- typedef can provide a simple name for a complicated type cast
- typedef can also be used to give names to unnamed types. In such cases, the typedef will be the only name for said type
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- typedef versus #define in C
- Is there any need of "long" data type in C and C++?
- Check if there is any pair in a given range with GCD is divisible by k
- Print Binary Equivalent of an Integer using Recursion in Java
- Java Program to Read a Grade & Display the Equivalent Description
- Java Program to Convert Binary Code Into Equivalent Gray Code Using Recursion
- What is the equivalent of ngShow and ngHide in Angular 2+?
- Can we access global variable if there is a local variable with same name?
- How to use getline() in C++ when there are blank lines in input?
- Problem with scanf() when there is fgets()/gets()/scanf() after it
- How to iterate any Map in Java
- Sorting a 2D Array according to values in any given column in Java
- Check if a String starts with any of the given prefixes in Java
- Execute main() multiple times without using any other function or condition or recursion in Java
- Java Program to Multiply two Matrices of any size
- Break Any Outer Nested Loop by Referencing its Name in Java
- Java Program to Interchange Any Two Rows in the Matrix
- Java Program to Interchange Any Two Columns in the Matrix
- Java Program to Print any Statement without Using the Main Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SHUBHAMSINGH10