Solve Error insert “Dimensions” to complete ReferenceType in Java

We usually get this error in java when we are trying to pass primitive data type in the generic type declaration. The reason we get this error because generic always expects the wrapper classes but gets the primitive data type.

Those who are unaware about primitive data types and wrapper classes.

Wrapper Classes

Wrapper classes are classes in java which contains primitive data types and primitive data type can be used as objects by the help of wrapper class. Wrapper classes contained by java.util.package in Java. With autoboxing a primitive data type is converted into corresponding object and with unboxing a wrapper class is converted into corresponding primitive data type.

Given below is the list of wrapper classes in Java:

  • Byte
  • Character
  • Short
  • Long
  • Integer
  • Double
  • Float
  • Boolean

Primitive Data Types

These are the most basic data types in Java which is predefined by language and having a fixed keyword for each of them. There are eight primitive data types in Java which are given below:

  • byte
  • char
  • short
  • long
  • int
  • double
  • float
  • boolean

Solve Error insert “Dimensions” to complete ReferenceType

Solve Error insert "Dimensions" to complete ReferenceType in Java

Here are some examples with this you can fix the error:

Output:

Exception in thread “main” java.lang.Error: Unresolved compilation problem:

       Syntax error, insert “Dimensions” to complete ReferenceType

 

       at MyProject/introduction.example.main(example.java:7

In the above example we are passing “int” which is primitive data type. We can fix this by replacing it with corresponding wrapper class “Integer”.

You can see now error has been fixed and we are getting our expected output.

Output:

[25, 57]

Similar steps can be followed for double and rest of the primitive data types.

Output:

Exception in thread “main” java.lang.Error: Unresolved compilation problem:

       Syntax error, insert “Dimensions” to complete ReferenceType

 

       at MyProject/introduction.example.main(example.java:7

We will replace the “double” with “Double” which is corresponding wrapper class for this.

Now error has been successfully fixed for “double” also and we are getting our output.

Output:

[25.0, 57.5]

I hope this guide will help you to solve the error. Comment down below if you still have any queries.

One comment

  • Alexandra

    Thanks for this very clear explanation. It was just the right amount of detail, the examples focused only on the question at hand, and most of all I appreciate that the tone was not condescending. Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *