Solved

A templated rectangle

Posted on 2007-11-29
3
247 Views
Last Modified: 2010-03-30
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
Comment
Question by:DJ_AM_Juicebox
3 Comments
 
LVL 14

Accepted Solution

by:
CPColin earned 500 total points
ID: 20375343
Which built-in Java class? The java.awt.Rectangle class uses ints.
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20375963
ah ok i was importing some other one using double as the type, this should be fine,

Thanks
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 20376674
This should work,
 
 
public class MyRectangle<T> {
  T l, r, t, b;
}
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now