3

Solve Error insert "Dimensions" to complete ReferenceType in Java - Th...

 3 years ago
source link: https://www.thejavaprogrammer.com/insert-dimensions-to-complete-referencetype/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:

  • Character
  • Short
  • 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:

  • short
  • double
  • float
  • boolean

Solve Error insert “Dimensions” to complete ReferenceType

Solve Error insert

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

package introduction;
import java.util.*;
public class example {
public static void main(String[] args) {
ArrayList<int> list=new ArrayList<>();
list.add(25.0);
list.add(57.5);
System.out.println(list);

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”.

package introduction;
import java.util.*;
public class example {
public static void main(String[] args) {
ArrayList<Integer> list=new ArrayList<>();
list.add(25);
list.add(57);
System.out.println(list);

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.

package introduction;
import java.util.*;
public class example {
public static void main(String[] args) {
ArrayList<double> list=new ArrayList<>();
list.add(25.0);
list.add(57.5);
System.out.println(list);

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.

package introduction;
import java.util.*;
public class example {
public static void main(String[] args) {
ArrayList<Double> list=new ArrayList<>();
list.add(25.0);
list.add(57.5);
System.out.println(list);

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK