Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

Why do we use autoboxing and unboxing in Java? And why it is needed?

1 Answer

0 votes
by (13.1k points)

Autoboxing is the converting of primitive data types into their respective wrapper classes like converting int into Integer. It is done by the java compiler. If the conversion happens the other way then it is unboxing.

Java offers these features so that developers can assign primitive datatypes using wrapper classes to Generic which only accepts objects as parameters thus allowing Generics to work indirectly with primitive data types.

According to Java Docs,” Autoboxing and unboxing lets developers write cleaner code, making it easier to read.”

Want to learn java? Check out the Java certification from Intellipaat.

Browse Categories

...