0

Im having problems when trying to initialize the variable:

Map<Sentence, Float>[] vectorValueSentences; // this is ok
/* but this is not */ vectorValueSentences = new HashMap<Sentence, Float>()[100];

I search on what to do but i didnt find any. I read that the object to be initialize has to be static but i dont find a way to declare the Map static.

Thank you for your help!

asked Oct 10, 2015 at 19:19
5
  • 1
    Can you include a fuller snippet? It's hard to understand without some more context. Commented Oct 10, 2015 at 19:21
  • If vectorValuesSentences is not declared before calling the line vectorValueSentences = new HashMap<Sentence, Float>()[100];, obviously its wrong Commented Oct 10, 2015 at 19:22
  • Because of how generics in Java work, you cannot directly create an array of a generic type (such as Map<Object, Object>[]). Or You are trying to do something else? More in: stackoverflow.com/questions/14917375/… Commented Oct 10, 2015 at 19:25
  • 2
    You should consider using a List of Maps. List<Map<Sentence, Float>> vectorValueSentences = new ArrayList<Map<Sentence, Float>>(); Commented Oct 10, 2015 at 19:26
  • Thank you guys! it was my first question here and solve it so quickly. Hope i can help in this community from now on Commented Oct 10, 2015 at 22:58

1 Answer 1

1
 HashMap<Sentence, Float>[] vectorValueSentences = new HashMap[100];
answered Oct 10, 2015 at 19:37
Sign up to request clarification or add additional context in comments.

1 Comment

Wooooooow, thank you! I can believe it was so simple and yet couldn't find it anywhere. Deepak Marathe, you are great :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.