Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10166

Re: alias for Integer

From David Lamb <dalamb@cs.queensu.ca>
Newsgroups comp.lang.java.programmer
Subject Re: alias for Integer
References <21374513.220.1321627842805.JavaMail.geo-discussion-forums@yqmj32>
Message-ID <EFyyq.45957$Ra6.20000@newsfe07.iad> (permalink)
Date 2011-11-21 15:38 -0500

Show all headers | View raw


On 18/11/2011 9:50 AM, jrobinss wrote:
> Now what I'd like is to write
>    public static Map<MatrixIndex, DbIndex>  myMap = ...;
>
> The advantage is that the code is auto-documented, but even better that the compiler will check that I never get mixed up in different indexes,
 > by relying on strong typing.
>
> Usually, I would do this by extending the relevant class. But here it's Integer, which is final.
>
> Questions:
> 1. is this a bad good idea, and I should proceed with Integer?
> 2. if not, how would you implement this?
> 3. is there any performance issue in defining my own classes instead of Integer?
>
> My current solution is to define my own classes for replacing Integer, such as:
>
> public final class MatrixIndex {
>    public final int value;
>    public MyIndex(int i) {value = i;}
> }

To me the critical question is: in what way do each of these different 
kinds of "integer" differ from each other and from the language-defined 
"Integer"?  Do they differ in upper and lower bounds, for example? is it 
important to keep track of where each number came from? is one of them a 
mere identifier (such as a lot number in a city plan) rather than 
something you could add and subtract from each other? All of those 
suggest that you need a new type(s) that "has an int" instead of "is an 
Integer".

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

alias for Integer jrobinss <julien.robinson2@gmail.com> - 2011-11-18 06:50 -0800
  Re: alias for Integer markspace <-@.> - 2011-11-18 07:11 -0800
  Re: alias for Integer Roedy Green <see_website@mindprod.com.invalid> - 2011-11-18 07:32 -0800
  Re: alias for Integer Lew <lewbloch@gmail.com> - 2011-11-18 07:34 -0800
    Re: alias for Integer jrobinss <julien.robinson2@gmail.com> - 2011-11-18 08:26 -0800
      Re: alias for Integer Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-18 18:00 +0000
      Re: alias for Integer markspace <-@.> - 2011-11-18 10:17 -0800
      Re: alias for Integer Roedy Green <see_website@mindprod.com.invalid> - 2011-11-18 20:30 -0800
    Re: alias for Integer Roedy Green <see_website@mindprod.com.invalid> - 2011-11-18 20:23 -0800
  Re: alias for Integer Jim Janney <jjanney@shell.xmission.com> - 2011-11-18 13:14 -0700
  Re: alias for Integer Patricia Shanahan <pats@acm.org> - 2011-11-18 12:43 -0800
  Re: alias for Integer jrobinss <julien.robinson2@gmail.com> - 2011-11-21 01:50 -0800
  Re: alias for Integer Robert Klemme <shortcutter@googlemail.com> - 2011-11-21 20:58 +0100
  Re: alias for Integer David Lamb <dalamb@cs.queensu.ca> - 2011-11-21 15:38 -0500

csiph-web