-2

I have a generic class "Property" that I want to put in a HashMap, but I get an "Unexpected token: >" error. I'm using Processing 2.2.1.

class MouseEvent extends Event{
  HashMap<String, Property> Args;
  MouseEvent(String type){
    Args = new HashMap<String, Property>();
    Args.put("mouseX", new Property<int>(mouseX)); //throws unexpected token
    Args.put("mouseY", new Property<int>(mouseY));
    Args.put("Button", new Property<int>(mouseButton));
    Args.put("Type", new Property<String>(type));
  }
}


class Property<T>{
  private T val;
  Poperty(T v){
    val = v;
  }
  void Set(T v){
    val = v;
  }
  T Get(){
    return val;
  }
}

What am I misunderstanding here? :/

Kelson Ball
  • 948
  • 1
  • 13
  • 30

1 Answers1

3

You cannot use primitive data types like int as the generic type. You have to use the corresponding Object i.e Integer.

Change your code to

Args.put("mouseX", new Property<Integer>(mouseX));

Also on side note follow java naming conventions. Variable/method names should be in camel case

HashMap<String, Property> args;
args = new HashMap<String, Property>();
//...
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • I tried that before posting this thread and got a similar error..but it is working now. I'm not sure what else has changed. – Kelson Ball Mar 26 '15 at 04:52