Re: methods with "short"-typed arguments.
- From: ojacobson@xxxxxxxxxxx
- Date: Tue, 7 Oct 2008 10:17:37 -0700 (PDT)
On Oct 7, 11:00 am, Lew <l...@xxxxxxxxxxxxx> wrote:
On Oct 7, 10:33 am, bugbear <bugbear@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Andreas Leitgeb wrote:
Given a method:
void foo (int x, short y) { ... }
How would I call it with an immediate value for the second argument?
foo ( 42, (short)43);
Or did I miss some postfix-char for short literals (like "L" for long)?
(according tohttp://mindprod.com/jgloss/jcheat.htmlthereisn't one)
I think you can "just do it"
http://www.janeg.ca/scjp/lang/literals.html
>> If an int literal is assigned to a short or
>> a byte and it's value is within legal
>> range, the literal is assumed to be a short or a byte.
I think parameter passing is same as assignment.
It pays to check.
<http://java.sun.com/docs/books/jls/third_edition/html/
conversions.html#5.3>
Method invocation conversions specifically do not include the implicit narrowing
of integer constants which is part of assignment conversion.
That all literals are of int type is a misfeature, IMO - the literal 1
should be of type byte, which can be wideningly-converted to any of
short, int, long, float, or double quite safely. Similarly, 128
should be of type short, and 32768 of type int. This'd probably
eliminate the need for an explicit 'L' qualifier: all literals greater
than 2,147,483,647 or less than -2,147,483,648 would logically be of
type 'long' without further effort.
We'd still need F for floats, though.
Alternately, the type suffixes for literals should be more thorough:
suffixes for literals of all numeric primitive types, including char.
The "implicit narrowing for assignment only" special case is confusing
and unnecessary.
-o
.
- Follow-Ups:
- Re: methods with "short"-typed arguments.
- From: Arne Vajhøj
- Re: methods with "short"-typed arguments.
- From: Tom Anderson
- Re: methods with "short"-typed arguments.
- From: Andreas Leitgeb
- Re: methods with "short"-typed arguments.
- References:
- methods with "short"-typed arguments.
- From: Andreas Leitgeb
- Re: methods with "short"-typed arguments.
- From: bugbear
- Re: methods with "short"-typed arguments.
- From: Lew
- methods with "short"-typed arguments.
- Prev by Date: Re: Storing data periodically on remote server
- Next by Date: Re: How to use @Resource annotation?
- Previous by thread: Re: methods with "short"-typed arguments.
- Next by thread: Re: methods with "short"-typed arguments.
- Index(es):
Relevant Pages
|