Results 1 to 4 of 4
- 11-19-2010, 08:33 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
switch() don't work with constant
any ideas?Java Code:class Class_A { public static final int TT_EOL = 10; } class TestSwitch { public static void main(String args[]) { Class_A obj = new Class_A(); int i = 10; switch (i) { case Class_A.TT_EOL : //but expression 'obj.TT_EOL' don't work System.out.println("i = " + i); break; } } }
- 11-19-2010, 08:49 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
You need to specify a compile time constant expression. (See JLS 15.28). TypeName.Identifier is OK if it refers to a constant variable, but the compiler is not going to go investigating obj to see that it's a constant 10.
-----------
obj.TT_EOL is wrong anyway ;)
- 11-19-2010, 08:56 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
*
Thank a lot! :)
- 11-19-2010, 08:59 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Similar Threads
-
static constant and performance
By felixtfelix in forum New To JavaReplies: 2Last Post: 08-31-2010, 01:43 PM -
Apache POI Excel: How can we keep the column headers in the diaplay part constant
By sarwan in forum Advanced JavaReplies: 2Last Post: 06-08-2010, 01:21 PM -
switch
By dj kourampies in forum New To JavaReplies: 17Last Post: 01-30-2009, 05:32 PM -
switch
By dj kourampies in forum New To JavaReplies: 2Last Post: 01-30-2009, 08:46 AM -
Constant size for JTextArea
By itaipee in forum AWT / SwingReplies: 1Last Post: 12-30-2008, 04:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks