This is homework but my teacher breezed through this part of the course during the lectures and I'm slightly lost.
We have to create a generic class Pair <A,B>
like this:
public Pair(A itemA, B itemB)
public A first()
public B second()
The class will be used to stored and item and it's weight, like for example: Pencil,15
I just need a slight push to be able to do this
All you really need to do is take the items in the constructor and store them in instance variables, which the
first()
andsecond()
methods can return. When you declare the instance variables, you can declare their types as justA
orB
.