Mahesh Gupta
Mahesh Gupta

Reputation: 2748

Creating object using Class class in Java

int.class returns an object of class type.

although there is a method to invoke constructor of a class, but since int.class represents primitive data type so no constructor are available.

Is there any way to create an int variable from int.class object ??

Upvotes: 2

Views: 181

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533442

You cannot create an instance of a primitive. Primitives are not Objects by definition. You can create an instance of a wrapper e.g. Integer which has a constructor which takes an int

Upvotes: 2

Related Questions