1

Here is code I want to declare an object of integer list in my class but it is showing error here. How do I add object of list integer to my class?

package JavaApplication1;

import java.io.Serializable;

/**
 *
 * @author user
 */

public class Word 
{

    private String path;
    private transient int frequency;
    private List<int> Lpaths;
}
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875

2 Answers2

1

You can't use int as the type parameter for List, it has to be an object type. So you need List<Integer>.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
1

You tried to declare a generic List using a primitive int as the type. This won't work, because only class types which extend Object are allowed. This is the code which achieves what you were trying to do:

private List<Integer> Lpaths;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360