[Solved] insert dimensions to complete referencetype

In this post, we will fix the error insert dimensions to complete referencetype. This error is a compile-time error. The root cause of this error is that you are passing a primitive data type(int, float, boolean, etc. ) into a generic type declaration but generic types always expect a Wrapper class object(Integer, Float, Boolean, etc.).

Read Also:  resource is out of sync with the filesystem error in eclipse

As always, we will produce the error first before moving on to the solution.

Fixed: insert dimensions to complete referencetype

1. Below code will give a compilation error in eclipse:

import java.util.*;
public class InsertDimensionsError {
    public static void main(String[] args) {        
Map<String, int> map;
} }

Output:
insert dimensions to complete referencetype

Explanation


In the above code, we are passing primitive data type 'int' instead of the wrapper class. We can fix this error by replacing it with the corresponding wrapper class i.e Integer.

Solution:

import java.util.*;
public class InsertDimensionsError {
    public static void main(String[] args) {
        
Map<String, Integer> map;
} }


2. Another example of insert dimensions to complete referencetype error is:

import java.util.*;
public class InsertDimensionsError2 {
    public static void main(String[] args) {
        
List<double> listObj = new ArrayList<>();
listObj.add(15.0); listObj.add(30.0); System.out.println(listObj); } }

Output:
insert dimensions to complete referencetype 2

Explanation


In the above example, we are passing primitive data type 'double' instead of the wrapper class. We can fix this error by replacing it with the corresponding wrapper class i.e Double as shown below:

Solution:

import java.util.*;
public class InsertDimensionsError2 {
    public static void main(String[] args) {
        
List<Double> listObj = new ArrayList<>();
listObj.add(15.0); listObj.add(30.0); System.out.println(listObj); } }

Output:
[15.0,30.0]


That's all for today, please mention in the comments in case you have any questions related to insert dimensions to complete referencetype.

About The Author

Subham Mittal has worked in Oracle for 3 years.
Enjoyed this post? Never miss out on future posts by subscribing JavaHungry