Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSanora Griffin
2,972 PointsGenerics in Java Fill in the blank to declare two type parameters for our new Pair class: class Pair _______ { }
I am putting in:
class Pair<T1, T2> { // omitted }
<T1, T2> turns greens but doesn't mark the question correct.
4 Answers
KRIS NIKOLAISEN
54,971 PointsThere are probably multiple correct answers. I tried <string,integer>, <integer,string> , <float, box>, <hour, day>, <key, value>, <dog, cat> and all passed.
Lauren Moineau
9,483 PointsThe official documentation says this:
Type Parameter Naming Conventions By convention, type parameter names are single, uppercase letters. This stands in sharp contrast to the variable naming conventions that you already know about, and with good reason: Without this convention, it would be difficult to tell the difference between a type variable and an ordinary class or interface name.
The most commonly used type parameter names are:
E - Element (used extensively by the Java Collections Framework)
K - Key
N - Number
T - Type
V - Value
S,U,V etc. - 2nd, 3rd, 4th types
You'll see these names used throughout the Java SE API and the rest of this lesson.
So maybe they were expecting two different uppercase letters (T and U for instance, although K and V is common practice for the Pair class, for key/value), or 2 different names (as KRIS NIKOLAISEN mentioned above).
Durim Fetahaj
5,946 PointsHello,
Just type <T, T> and that's it.
Christopher Andrews
Courses Plus Student 1,477 PointsDurim hit the head on the nail here people. 👌👍
Ahmed Matar
2,231 PointsHey guys, the right answer is :
class Pair
<firstThing, secondThing> { // omitted }