Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 13886 invoked from network); 2 Dec 2004 15:04:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Dec 2004 15:04:34 -0000 Received: (qmail 9203 invoked by uid 500); 2 Dec 2004 15:03:51 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 9176 invoked by uid 500); 2 Dec 2004 15:03:51 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 9160 invoked by uid 99); 2 Dec 2004 15:03:51 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=DNS_FROM_RFC_ABUSE X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from workstation5.qas.com (HELO mail3.qas.com) (195.172.82.5) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 02 Dec 2004 07:03:49 -0800 Received: from orion.qas.com (orion.qas.com [150.150.100.34]) by mail3.qas.com (Content Technologies SMTPRS 4.3.17) with ESMTP id for ; Thu, 2 Dec 2004 15:03:44 +0000 X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: final variable value lost in anonynous inner class Date: Thu, 2 Dec 2004 15:03:44 -0000 Message-ID: <5684A7E6FB10504393A2806C1F4C021005AF7F35@orion.qas.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: final variable value lost in anonynous inner class Thread-Index: AcTYf6lyxohqBGxUQ++nxUA02MH4UAAAG5pg From: "Allistair Crossley" To: "Tomcat Users List" X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N this looks like a school assignment ;) > -----Original Message----- > From: Oliver Jonas [mailto:oliver@jonas.com] > Sent: 02 December 2004 15:00 > To: tomcat-user@jakarta.apache.org > Subject: JSP: final variable value lost in anonynous inner class >=20 >=20 > Hi, >=20 > =20 >=20 > I have the following test JSP (see below.) When I use the=20 > final variable > obtained by class A inside an anonymous subclass of B the=20 > values are lost. > However, if I define the final variables' values directly=20 > without using > class A it works. Both cases work fine when using this as a=20 > normal Java > class, so it seems related to JSP's or Tomcat. >=20 > =20 >=20 > The catalina.out output is: >=20 > =20 >=20 > 1/ str1=3Dstr1 >=20 > 1/ str2=3Dstr2 >=20 > 1/ i1=3D1234 >=20 > 1/ i2=3D1234 >=20 > 2/ str1=3Dnull >=20 > 2/ str2=3Dstr2 >=20 > 2/ i1=3D0 >=20 > 2/ i2=3D1234 >=20 > a =3D=3D null >=20 > =20 >=20 > This is Tomcat 4.1.30 with VM 1.4.2_06. >=20 > =20 >=20 > =20 >=20 > Do you know what is wrong or how to bypass this? >=20 > =20 >=20 > Thanks, >=20 > Oliver. >=20 > =20 >=20 > <%! >=20 > public static class A >=20 > { >=20 > private String s; >=20 > private int i; >=20 > =20 >=20 > public A() { >=20 > s =3D "str1"; >=20 > i =3D 1234; >=20 > } >=20 > =20 >=20 > public String getS() { >=20 > return s; >=20 > } >=20 > =20 >=20 > public int getI() { >=20 > return i; >=20 > } >=20 > } >=20 > =20 >=20 > public A getA() { >=20 > return new A(); >=20 > } >=20 > =20 >=20 > public static abstract class B >=20 > { >=20 > public B() >=20 > { >=20 > run(); >=20 > } >=20 > =20 >=20 > public abstract void run(); >=20 > } =20 >=20 > =20 >=20 > public B getB() >=20 > { =20 >=20 > final A a =3D getA(); >=20 > =20 >=20 > final String str1 =3D a.getS(); >=20 > final String str2 =3D "str2"; >=20 > =20 >=20 > final int i1 =3D a.getI(); >=20 > final int i2 =3D 1234; >=20 > =20 >=20 > System.out.println("1/ str1=3D" + str1); >=20 > System.out.println("1/ str2=3D" + str2); >=20 > System.out.println("1/ i1=3D" + i1); >=20 > System.out.println("1/ i2=3D" + i2); >=20 > =20 >=20 > return new B() >=20 > { >=20 > public void run() >=20 > { >=20 >=20 > System.out.println("2/ > str1=3D" + str1); >=20 > System.out.println("2/ > str2=3D" + str2); >=20 > =20 >=20 > =20 > System.out.println("2/ i1=3D" > + i1); >=20 > =20 > System.out.println("2/ i2=3D" > + i2); >=20 > =20 >=20 > if(a =3D=3D null) > System.out.println("a =3D=3D null"); >=20 > } >=20 > }; >=20 > } >=20 > %> >=20 > =20 >=20 > <% =20 >=20 > getB(); >=20 > %> >=20 > =20 >=20 >=20 =20 ------------------------------------------------------- QAS Ltd. Developers of QuickAddress Software www.qas.com Registered in England: No 2582055 Registered in Australia: No 082 851 474 ------------------------------------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org