KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > HintTypeTest


1 /* HintTypeTest Copyright (C) 1999 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; see the file COPYING. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: HintTypeTest.java,v 1.4 1999/08/19 15:16:59 jochen Exp $
18  */

19
20
21 /**
22  * The primitive types can give some headaches. You almost never can say
23  * if a local variable is of type int, char, short etc. <p>
24  *
25  * Most times this doesn't matter this much, but with int and character's
26  * this can get ugly. <p>
27  *
28  * The solution is to give every variable a hint, which type it probably is.
29  * The hint reset, when the type is not possible. For integer types we try
30  * to set it to the smallest explicitly assigned type. <p>
31  *
32  * Some operators will propagate this hint.<p>
33  */

34 public class HintTypeTest {
35
36     public void charLocal() {
37     String JavaDoc s= "Hallo";
38     for (byte i=0; i< s.length(); i++) {
39         char c = s.charAt(i);
40         if (c == 'H')
41         // The widening to int doesn't occur in byte code, but
42
// is necessary. This is really difficult.
43
System.err.println("H is "+(int)c);
44         else
45         System.err.println(""+c+" is "+(int)c);
46     }
47     }
48 }
49
50
51
Popular Tags