From: SourceForge.net <no...@so...> - 2005-05-13 22:36:26
|
Bugs item #1201699, was opened at 2005-05-13 17:36 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=438935&aid=1201699&group_id=44253 Category: Interactions Group: Annoying Status: Open Resolution: None Priority: 5 Submitted By: rlh (rhalterman) Assigned to: Nobody/Anonymous (nobody) Summary: final instance constants not constant Initial Comment: DrJava 20050519-0024 Windows, Linux, and Mac OS X versions Create this class and compile it: public class FinalTest { public final double PI = 3.14159; } The following Interactions sequence behaves consistently on all the platforms: > FinalTest f = new FinalTest(); > f.PI = 2.5; > f.PI 2.5 But, DrJava's compiler correctly disallows the following code: public class TestFinalTest { public static void main(String[] args) { FinalTest f = new FinalTest(); f.PI = 2.5; } } 1 error found: File: TestFinalTest.java [line: 4] Error: cannot assign a value to final variable PI Note: If the constant is static (which is ordinarily how constants are handled), the interactions pane WILL throw an exception about the field being final: public class FinalTest { public static final double PI = 3.14159; } > FinalTest f = new FinalTest(); > f.PI = 2.5; IllegalAccessException: Field is final at sun.reflect. ... (exception report continues) DrJava 20050519-0024 Linux (Debian Woody) and Windows (XP Professional, SP2): java version "1.5.0_03" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07) Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing) Mac OS X (Tiger--10.4): java version "1.5.0_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-56) Java HotSpot(TM) Client VM (build 1.5.0_02-36, mixed mode, sharing) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=438935&aid=1201699&group_id=44253 |