Java- Getting unexpected type error when declaring new generic set

Van

I thought I knew what I was doing with generics, but apparently not.

ArraySetList<char> setA = new ArraySetList<char>();

When compiled gives:

error: unexpected type
ArraySetList<char> setA = new ArraySetList<char>();
             ^
required: reference
found:    char

As well as the same error for all subsequent char's. I'm wondering how to declare a new ArraySetList of characters.

Here are all my files.

http://pastebin.com/4h37Xvu4     // ArraySetList (extends ArrayUnsortedList)
http://pastebin.com/FxmynzkC     // Driver
http://pastebin.com/CgVA0zjY     //ArrayUnsortedList (implements ListInterface)
http://pastebin.com/3iXrCsCc     //ListInterface\
An SO User

Java Generics work for objects and not for primitive data types. If you, however, need to store primitive data types, you will need to use their corresponding wrapper class objects.
These classes just "wrap" around the primitive data type to give them an object appearance.

For char, the corresponding wrapper class is Character and hence, you must write your line of code as so:

ArraySetList<Character> setA = new ArraySetList<Character>();   

Please read: http://docs.oracle.com/javase/tutorial/java/data/numberclasses.html

When you add elements, however, you will add normal char. That is because Java will automatically convert it into Character for you and back to char automatically, if need be. This is called auto-boxing conversion.

Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer, a double to a Double, and so on. If the conversion goes the other way, this is called unboxing.

source: http://docs.oracle.com/javase/tutorial/java/data/autoboxing.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting a "No instance of Applicative" error when declaring a Monad

From Dev

Java unexpected type error

From Dev

error when declaring a new object in a UIViewController in swift

From Dev

Error 'Syntax error: "(" unexpected' when declaring arrays in bash

From Dev

Error 'Syntax error: "(" unexpected' when declaring arrays in bash

From Dev

Java: Getting the generic type of a lambda

From Dev

Java Generic getting type parameter

From Dev

Java Generic getting type parameter

From Dev

Java: Getting the generic type of a lambda

From Dev

gcc error when declaring reference to reference type

From Dev

Syntax error near unexpected token "(" when declaring arrays in bash

From Dev

Difference between using wildcards and declaring generic type in abstract method in Java

From Dev

Java Compile error when return Generic Class type

From Dev

Declaring object of arrays in Typescript; getting error Type '{}' missing the following properties

From Dev

Declaring object of arrays in Typescript; getting error Type '{}' missing the following properties

From Dev

Error: not a statement when declaring a boolean in Java

From Dev

Declaring a type as a subset of a set

From Dev

Getting syntax error when declaring FOREIGN KEYS in MYSQL (using innoDB)

From Dev

Generic type error for android java

From Dev

Why am I getting an 'Invalid Parameters' error when the generic type constraints are the same?

From Dev

Just passing Java generic type through, but still getting not-within-its-bound error

From Dev

Why do I keep on getting this error "error: unexpected type"

From Dev

Inferring a generic type from a generic type in Java (compile time error)

From Dev

Keep getting unexpected type

From Dev

unexpected behavior when using calendar type in java

From Dev

Compilation error when overriding a generic type method

From Dev

Error when returning interface with generic type

From Dev

Error when using operators with a generic type

From Dev

Declaring method returning generic subtype from a declaring type

Related Related

  1. 1

    Getting a "No instance of Applicative" error when declaring a Monad

  2. 2

    Java unexpected type error

  3. 3

    error when declaring a new object in a UIViewController in swift

  4. 4

    Error 'Syntax error: "(" unexpected' when declaring arrays in bash

  5. 5

    Error 'Syntax error: "(" unexpected' when declaring arrays in bash

  6. 6

    Java: Getting the generic type of a lambda

  7. 7

    Java Generic getting type parameter

  8. 8

    Java Generic getting type parameter

  9. 9

    Java: Getting the generic type of a lambda

  10. 10

    gcc error when declaring reference to reference type

  11. 11

    Syntax error near unexpected token "(" when declaring arrays in bash

  12. 12

    Difference between using wildcards and declaring generic type in abstract method in Java

  13. 13

    Java Compile error when return Generic Class type

  14. 14

    Declaring object of arrays in Typescript; getting error Type '{}' missing the following properties

  15. 15

    Declaring object of arrays in Typescript; getting error Type '{}' missing the following properties

  16. 16

    Error: not a statement when declaring a boolean in Java

  17. 17

    Declaring a type as a subset of a set

  18. 18

    Getting syntax error when declaring FOREIGN KEYS in MYSQL (using innoDB)

  19. 19

    Generic type error for android java

  20. 20

    Why am I getting an 'Invalid Parameters' error when the generic type constraints are the same?

  21. 21

    Just passing Java generic type through, but still getting not-within-its-bound error

  22. 22

    Why do I keep on getting this error "error: unexpected type"

  23. 23

    Inferring a generic type from a generic type in Java (compile time error)

  24. 24

    Keep getting unexpected type

  25. 25

    unexpected behavior when using calendar type in java

  26. 26

    Compilation error when overriding a generic type method

  27. 27

    Error when returning interface with generic type

  28. 28

    Error when using operators with a generic type

  29. 29

    Declaring method returning generic subtype from a declaring type

HotTag

Archive