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

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
0
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
1 Solution
 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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