A templated rectangle

Hi,
I have a rectangle class like:

public class MyRectangle
{
     int l, r, t, b;
}

because using the built in java one has doubles for the members instead of int and its really annoying to use with graphics drawing. How can I update it to just 'template' the type, something like:

public class MyRect<int>
{
     int l, r, t, b;
}
public class MyRect<double>
{
    double l, r, t, b;
}

etc?

Thanks
DJ_AM_JuiceboxAsked:
Who is Participating?
 
CPColinSenior Java ArchitectCommented:
Which built-in Java class? The java.awt.Rectangle class uses ints.
0
 
DJ_AM_JuiceboxAuthor Commented:
ah ok i was importing some other one using double as the type, this should be fine,

Thanks
0
 
Ajay-SinghCommented:
This should work,
 
 
public class MyRectangle<T> {
  T l, r, t, b;
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.