• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

<K,V> ???

Hi.

What is ment by:  <K,V>
I've seen it in a few different places, including the HashMap source code, ie:

    public class HashMap<K,V>

What does it mean? How does it work? Why would you use it?

Cheers!
0
InteractiveMind
Asked:
InteractiveMind
  • 4
  • 2
1 Solution
 
CEHJCommented:
It's generics syntax for strong compile-time type checking. It says " i'm going to map keys of type K to values of type V" Incorrect types will be caught at compile time
0
 
CEHJCommented:
Try compiling this:

                  Map<Integer, String> map = new HashMap<Integer, String>();
                  map.put(2, "two");
                  map.put("3", "three");
0
 
InteractiveMindAuthor Commented:
Okay, is this something that Java Developers often use? Or can it be avoided??

Cheers man.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
It's version 1.5-specific. It can be avoided
0
 
InteractiveMindAuthor Commented:
Ah, I see! Your example done it for me. :-)

Cheers.. again.  ^_^
0
 
CEHJCommented:
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now