Is it safe to extend Reference sub-classes?

I'd like to extend SoftReference to include an instance field for the referent's ID. I'll use this to remove the referent's reference from a Map keyed by the ID. Is this acceptable?

Yes, this can be a useful thing to do. That is why the Reference classes are not final.
If you are putting your References into a ReferenceQueue, then extra state information stored in the References can be used to determine what actions to take when they are removed from the queue.

Similar Messages

  • Extending and sub classing

    i'm experimenting with extending and subclassing components in flex. i am trying to add an event listener to the datagridcolumn. i want to add a function to occur when i click the column (using a mouseclickevent).
    each of my pieces of data in the datagrid have a custom style to look like a hyperlink (blue and underlined). the user will drill into details behind the numbers they see. i got this to work with itemClick and i found some good code to use for totaling the datagrid numbers by using the code from Alex's Flex closet http://blogs.adobe.com/aharui/2008/03/flex_3_datagrid_footers.html
    my problem is i'm finding that i cannot use the styling or itemClick function to work with the  footers and so am trying to subclass another footerdatagridcolumn to  have a mouse click event to do something with. i'd like for the footer data to be blue and underlined as well if thats possible but not sure how to refer to my Flex css style in AS3. see the attached screenshot i'm trying to get the footer to work with itemClick and have the same style of blue and underlined for the columns that are highlighted below.

    DataGridColumns do not dispatch mouse events.  I would listen to the
    DataGrid and use mouseEventToItemRenderer as needed.

  • How to reference the class-instance, created in parent class.

    Hi, I have following scenario. During compilation I am gettting error message -- "cannot resolve symbol - symbol : Variable myZ"
    CODE :
    under package A.1;
         ClassZ
         Servlet1
              ClassZ myZ = new ClassZ;
    under package A.2;
         Servlet2 extends Servlet1
              myZ.printHi();
    How to reference the class-instance created in the parent class?

    some corrections ...
    under package A.1;
         ClassZ
         Servlet1
              init()
                   ClassZ myZ = new ClassZ;
    under package A.2;
         Servlet2 extends Servlet1
              myZ.printHi();

  • Is it possible to OVERLOAD a super-class method in a sub-class?

    Hi all,
    I have a query that
    Is it possible to OVERLOAD a super-class method in a sub-class?
    If it is possible, please give me an example.
    Thanks,
    Hari

    Hi,
    Is the method int Display(int a){} overloading
    the super-class's void Display() method? If
    possible, please clarify this and how it would be
    method overloading?
    hanks,
    Hari
    Hi Hari,
    Yes, it is possible. Look at this piece of code:
    class Senior
         void Display()
              System.out.println("Super class method");
    class Junior extends Senior
         int Display(int a)
              System.out.println("Subclass method: "+a);
              return(a+10);
         }> }
    class example
         public static void main(String args[])
              Junior j = new Junior();
              j.Display();
    System.out.println("Subclass method
    od "+j.Display(5));
    Is this what you were asking? Hope this helped.Hi,
    I guess you guys are confused here...
    Overloading is achieved by methods in the same class...
    Overriding is across a superclass subclass methds.

  • Java Sub-Classing Error.  Please Help!

    I am trying to understanding some classing sub-classing and the convertion exercise. The errors appear with the code at the bottom at compilation.
    HelloWorld.java:7: cannot resolve symbol
    symbol : method uniqueInSubSayHello()
    location: class SayHello
    sh2.uniqueInSubSayHello();
    ^
    HelloWorld.java:11: cannot resolve symbol
    symbol : method uniqueInSubSayHello()
    location: class SayHello
    sh2.uniqueInSubSayHello();
    ^
    class HelloWorld {
         public static void main (String args[]) {
              subSayHello subsh=new subSayHello();
              SayHello sh2=subsh;
              sh2.haha();
              sh2.uniqueInSubSayHello();
         int callUnique() {
              sh2.uniqueInSubSayHello();
    class SayHello {
         public SayHello() {
         public void haha() {
    class subSayHello extends SayHello {
         public subSayHello() {
         void uniqueInSubSayHello() {

    On line 7, sh2 points to an object of type SayHello (as you assigned two lines earlier) and therefore does not know about method UniqueUnSubSayHello.
    On line 11, sh2 has not been declared, since sh2 is not a variable declared globally within class SayHello. Therefore, it is not found.
    Best regards,
    Cemil

  • Do sub classes get their own copy of base class static members?

    Hi,
    I am sub classing a certain classwhich has a static member boolean used for status updating. I have two sub classes, each needing its own static copy of the boolean. Do they get their own copy, or must I redeclare the member in each sub class?
    AC

    You must re-declare them (hiding the superclass member) if you wish the subclass members to be "independent".
    class Coin {
        public static int FOO;
        public static int BAR;
    class Coin2 extends Coin {
        public static int BAR = 2;
        public static void main(String[] args) {
            FOO = 1;
            System.out.println("Coin FOO  = " + Coin.FOO);  // 1
            System.out.println("Coin2 FOO = " + Coin2.FOO); // 1
            System.out.println("Coin BAR  = " + Coin.BAR);  // 0
            System.out.println("Coin2 BAR = " + Coin2.BAR); // 2
    }HTH! :o)

  • Calling sub class method from superclass constructure

    hi all
    i have seen a program in which a super class constructure class methods of sub class before initialization of fields in subclass ,i want how this is posibble ?
    thanks in advance

    Hear is the code n other thing i have used final variable without initialization n compiler dosen't report error
    abstract class Test
    public Test()
    System.out.println("In DemoClass Constructer");
    this.show();
    public void show()
    System.out.println("In DemoClass Show() method");
    class Sub1 extends Test
    private final float number;
    public Sub1(float n)
    this.number=n;
    System.out.println((new StringBuilder()).append("Number is==").append(number).toString());
    int j;
    public void show()
    System.out.println("In Sub1 Class Show method ");
    public class DemoClass
    public static void main(String s[])
    Sub1 obj1=new Sub1(5);
    Sub1 obj2=new Sub1(6);
    thanks for reply

  • Why are protected fields not-accessible from sub-classed inner class?

    I ran across a situation at work where we have to sub-class an inner class from a third-party package. So, it looks something like this...
    package SomePackage;
    public class Outer {
       protected int x;
       public class Inner {
    package OtherPackage;
    public class NewOuter extends Outer {
       public class NewInner extends Outer.Inner {
    }Now the NewInner class needs to access protected variables in the Outer class, just like the Inner class does. But because NewOut/NewInner are in a different package I get the following error message.
    Variable x in class SomePackage.Outer not accessible from inner class NewOuter. NewInner.You can still access those protected variables from the NewOuter class though. So, I can write accessor methods in NewOuter for NewInner to use, but I am wondering why this is. I know that if NewOuter/NewInner are in the same package as Outer/Inner then everything works fine, but does not when they are in different packages.
    I have to use JDK1.1.8 for the project so I don't know if there would be a difference in JDK1.2+, but I would think that nothing has changed. Anyway, if you know why Java disallows access as I have detailed please let me know.

    Although I don't have the 1.1.8 JDK installed on my system, I was able to compile the following code with the 1.3.1_01 JDK and run it within a Java 1.1.4 environment (the JVM in the MSIE 5.5 browser). As long as you don't access any of the APIs that were introduced with 1.2+ or later, the classes generated by the JDK 1.2+ javac are compatible with the 1.1.4+ JVM.
    //// D:\testing\SomePackage\Outer.java ////package SomePackage ;
    public class Outer {
        protected int x ;
        public Outer(int xx) {
            x = xx ;
        public class Inner {
    }//// D:\testing\OtherPackage\NewOuter.java ////package OtherPackage;
    import SomePackage.* ;
    public class NewOuter extends Outer {
        public NewOuter(int xx) {
            super(xx) ;
        public class NewInner extends Outer.Inner {
            public int getIt() {
                return x ;
    }//// D:\testings\Test.java ////import OtherPackage.* ;
    import java.awt.* ;
    import java.applet.* ;
    public class Test extends Applet {
        public void init () {
            initComponents ();
        private void initComponents() {
            add(new Label("x = ")) ;
            int myx = new NewOuter(3288).new NewInner().getIt() ;
            TextField xfld = new TextField() ;
            xfld.setEditable(false) ;
            xfld.setText(Integer.toString(myx)) ;
            add(xfld) ;
    }//// d:\testing\build.cmd ////set classpath=.;D:\testing
    cd \testing\SomePackage
    javac Outer.java
    cd ..\OtherPackage
    javac NewOuter.java
    cd ..
    javac Test.java//// d:\testing\Test.html ////<HTML><HEAD></HEAD><BODY>
    <APPLET CODE="Test.class" CODEBASE="." WIDTH=200 HEIGHT=100></APPLET>
    </BODY></HTML>

  • Sub Class in applet

    I have written an applet that does a mathematical operation on numbers then shows a diagram on the clicking of a button.
    On the clicking of the button I removed the previous two panels and repainted the GUI with the diagram, created using a sub class/ The class header and constuctor is shown below for the sub class.
    In netbeans, using applet viewer this works.
    Yet for some reason when the applet code is used in a web page the main applet comes up fine and is operational but when clicking the diagram button nothing happens.
    II would appreciate any help going?
    Thanks
      public class VennChart extends JPanel
          /**provides a venn diagram of fucntion
           *@param g is graphics component
          public void paintComponent(Graphics g)
             //frame initialisation
             super.paintComponent(g);
             //code to draw diagram
    if(ae.getSource()==graph)
                pane.remove(holder);
                pane.remove(status);
                pane.repaint();
                pane.add(exit, "North");
                VennChart chart = new VennChart();
                temp = chart; //temporary JPanel variable to hold diagram
                pane.add(temp, "Center");
                pane.validate();
    }

    What error message do you get in the java console?

  • How do i Index on a Sub class

    Hi,
    Please let me know if there is a way to index on the vairable in a sub class.
    Thanks & regards,
    Ebe

    Hi Cameron,
    The design of the Object is as follows.
    Object
    --- getSubObjectList() - Returns SubObjectList
    ----- Contains the list of SubObject
    ---- SubObject Contains attributes which i query upon.
    Please let me know a way how to index on these attributs. Please find the code am using below
    Below is the extract method of my Extractor Class
    public final class ObjectGraphNavigationValueExtractor extends
    AbstractExtractor implements ValueExtractor, ExternalizableLite
    public Object extract(Object object) {
    if(this.path.equals("attr1") || this.path.equals("attr2")){
    MyObject obj =
    (MyObject)object;
    SubObjectList subList = (SubObjectList) obj.getSubObjectList();
    Object aoExtracted[] = subList.toArray();
    for(int i=0;i<aoExtracted.length;i++){
    SubObject objSubObject =
    (SubObject) aoExtracted;
    return new BeanWrapperImpl(SubObject).getPropertyValue(this.path);
    return new BeanWrapperImpl(object).getPropertyValue(this.path);
    I have applied index as follows.
    cache.addIndex(new ObjectGraphNavigationValueExtractor("attr1"),true,null);
    cache.addIndex(new ObjectGraphNavigationValueExtractor("attr2"),true,null);
    Regards,
    Ebe

  • Instantiation of similar object over a super class deciding the sub class

    Hello all
    First, sorry if I'm duplicating an already answered question. I didn't searched very deep.
    Initial position:
    I have 2 Object (A1 and A2) which share the most (about 90%) of their instance variables an the associated methods. The values of the instance variables are retrieved in the real implementation from a stream. Depending of the data of the stream, I have to instantiate either a A1 or A2 object.
    A test implementation (using an int in case of the stream):
    The super class A:
    package aaa;
    public class A
      protected int version = -1;
      protected String name = null;
      protected AE ae = null;
      protected A()
      protected A(int v)
        // Pseudo code
        if (v > 7)
          return;
        if (v % 2 == 1)
          this.version = 1;
        else
          this.version = 2;
      public final int getVersion()
        return this.version;
      public final String getName()
        return this.name;
      public final AE getAE()
        return this.ae;
    }The first sub class A1:
    package aaa;
    public final class A1 extends A
      protected A1(int v)
        this.version = v;
        this.name = "A" + v;
        this.ae = new AE(v);
    }The second subclass A2:
    package aaa;
    import java.util.Date;
    public final class A2 extends A
      private long time = -1;
      protected A2(int v)
        this.version = v;
        this.name = "A" + v;
        this.time = new Date().getTime();
        this.ae = new AE(v);
      public final long getTime()
        return this.time;
    }Another class AE:
    package aaa;
    public class AE
      protected int type = -1;
      protected AE(int v)
        // Pseudo code
        if (v % 2 == 1)
          this.type = 0;
        else
          this.type = 3;
      public final int getType()
        return this.type;
    }To get a specific object, I use this class:
    package aaa;
    public final class AFactory
      public AFactory()
      public final Object createA(int p)
        A a = new A(p);
        int v = a.getVersion();
        switch (v)
        case 1:
          return new A1(v);
        case 2:
          return new A2(v);
        default:
          return null;
    }And at least, a class using this objects:
    import aaa.*;
    public final class R
      public static void main(String[] args)
        AFactory f = new AFactory();
        Object o = null;
        for (int i = 0; i < 10; i++)
          System.out.println("===== Current Number is " + i + " =====");
          o = f.createA(i);
          if (o instanceof aaa.A)
            A a = (A) o;
            System.out.println("Class   : " + a.getClass().getName());
            System.out.println("Version : " + a.getVersion());
            System.out.println("Name    : " + a.getName());
            System.out.println("AE-Type : " + a.getAE().getType());
          if (o instanceof aaa.A2)
            A2 a = (A2) o;
            System.out.println("Time    : " + a.getTime());
          System.out.println();
    Questions:
    What would be a better way to encapsulate the logic into their respective objects ? Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?
    Thanks in advance
    Andreas

    Hello jduprez
    First, I would thank you very much for taking the time reviewing my problem.
    Just for the record: have you considered regular serialization? If you control the software at both ends of the stream, you could rely on standard serialization mechanism to marshall the objects and unmarshall them automatically.In my case, I can't control the other site of the stream. At the end, the data comes from a FileInputStream and there aren't objects on the other site, only pur binary data.
    - It seems you have one such factory class. Then you already have encapsulated the "determine class" logic, you don't need to add such logic in superclass A.I thought from an OO view, that the super class A is responsible of doing that, but that's where the problem starts. So at the end, it's better doing it in the factory class.
    - A itself encapsulates the logic to load its own values from the stream.
    - A1 and A2 can encapsulate the logic to load their own specific value from a stream (after the superclass' code has loaded the superclass' attributes values).
    My advise would be along the lines of:
    public class A {
    .... // member variables
    public void load(InputStream is) {
    ... // assign values to A's member variables
    // from what is read from the stream.
    public class A1 extends A {
    ... // A1-specific member variables
    public void load(InputStream is) {
    super.load(is);
    // now read A1-specific values
    public class AFactory {
    public A createA(InputStream is) {
    A instance;
    switch (is.readFirstByte()) {
    case A1_ID:
    a = new A1();
    break;
    case A2_ID:
    a = new A2();
    break;
    a.load(is);
    }The example above assumes you have control over the layout of the data in the stream (here for a given A instance, the attributes defined in A are read first, then come the subclass-specific attributes.
    The outcome is: you don't have to create a new A( ) to later create another instance, of a subclass.I like the idea. In the AFactory, is the "A instance;" read as "A a;" ?
    Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?Note I initially read this question as "can an instance of a class mutate into another class", to which the answer is no (an object has one single, immutable class; it is an instance of this class, and of any superclass and superinterface, but won't change its class at runtime).Yes, I have been thinking about a way for mutating into a subclass to keep the already initialized values from the A class without copying or parsing again. But preventing an instance of an A class will be my way. So, in this aspect, Java didn't changed in the last 10 years... It's a long time ago I've used Java for some real projects.
    You can, however, create an instance of another class, that copies the values off a priori A instance. Your example code was one way, another way could be to have a "copy constructor":
    public class A {
    public A(A model) {
    this.att1 = model.att1;
    this.att2 = model.att2;
    public class A1 {
    public A1(A model) {
    super(model);
    ... // do whatever A1-specific business
    )Still, I prefer my former solution less disturbing: I find the temporary A instance redundant and awkward.Nice to know. I prefer the first solution too.
    Thank you again for the help and advices. My mind is searching sometimes for strange solutions, where the real is so close ;-)
    Andreas

  • Is Overloading possible in Sub class

    In every book I found that Overloading means method with the same name and with different parameter define in same class.
    But is possible if I define method with the same name and with different parameter in Sub class?
    Like example given below :
    public class OverLadingTest {
         public void test(int a, int b) {
              System.out.println("Inside test(int a, int b)");
         public static void main(String args[]){
                   OverloadedSubclass overloadedSubclass = new OverloadedSubclass();
                   overloadedSubclass.test(10.20,10.20);
    class OverloadedSubclass extends OverLadingTest {
         public void test(double a, double b) {
              System.out.println("Inside test(double a, double b)");
    Thanks in advance.

    The nays have it!
    package forums;
    class Singularity
      public void test(int a) {
        System.out.println("Singularity.test(int a)");
    class Universe extends Singularity
      @Override
      public void test(int a) {
        System.out.println("Universe.test(int a)");
      public void test(int a, int b) {
        System.out.println("Universe.test(int a, int b)");
    public class OverloadingTest
      public static void main(String args[]) {
        Singularity s = new Universe();
        s.test(10);
        s.test(10, 20);
    compile
    C:\Java\home\src\forums>"C:\Program Files\Java\jdk1.6.0_12\bin\javac.exe" -Xlint -d C:\Java\home\classes -cp c:\java\home\src; C:\Java\home\src\forums\OverloadingTest.java
    C:\Java\home\src\forums\OverloadingTest.java:27: test(int) in forums.Singularity cannot be applied to (int,int)
        s.test(10, 20);
         ^
    1 errorI'd say that's pretty conclusive, wouldn't you? Go read up on Java's definition of a [method signature|http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html]... It's not just the name, putz!
    Cheers. Keith.

  • How can a sub class access exisiting stage item?

    i have a button on the stage. the document class loads two
    sub classes. how do you get the sub class to access/work with a
    stage item that is already on the display list?
    as3.0 is killing me!!! grrrr...
    thanks!

    The document class mapDC:
    package com.main{
    // this is the main document class for the rextag map
    appllication
    // import movie clip to extend to use on stage
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import com.main.tools.mapTools;
    public class mapDC extends MovieClip {
    // instance of class
    public function mapDC() {
    trace("MainMap initialized");
    new mapTools(stage);
    public function test() {
    trace("here at test");
    The mapTools Class:
    package com.main.tools{
    // import
    import flash.events.MouseEvent;
    import flash.display.*;
    // this class will contain all the move methods and
    functions
    public class mapTools {
    private var stage:Stage;
    function mapTools(targetStage) {
    trace("Map tools initialized");
    stage = targetStage;
    stage.root.mapSection.eastArrow.addEventListener(MouseEvent.ROLL_OVER,testOutput);
    //---------- test output function
    public function testOutput(evt:MouseEvent) {
    trace("worked");
    }

  • Method of JUErrorHandlerDlg sub class

    Hi Forum
    i am working jClint/Swing Application in jDevloper.And
    i want to use own custom messageBox rather than exception
    through from database BC4J.
    I fund JUErrorHandlerDlg sub class for exception through
    so how to method use for this.
    please reply me some code.
    javed

    Thanks! for reply
    But until i found problem ,how to catch exception
    throw by bc4j(Jbo error meassage),exception has a
    error number(like jbo-10426).
    So using this error number how to use
    this exception,In order to own message dilog.
    please reply me some code,
    use in our class as
    public class subJUErrorHandlerDlg extends
    JUErrorHandlerDlg
    public subJUErrorHandlerDlg()
    // i write bootstrap application
    JUMetaObjectManager.setBaseErrorHandler(new subJUErrorHandlerDlg());

  • Stage reference from class

    How do I reference the stage from a class? I need to add eventlisteners to the
    stage for mouse movement. I also need to add custom cursors. I always get an error when I try to reference stage
    . anything. Or event if I do this:
    var stageRef:Stage;
    then later: stageRef.stage.addEventList.....
    What am I missing or not understanding?

    I cannot get it to work. Here is my code:
    package com {
    // core
    import flash.display.MovieClip;
    import flash.display.Stage;
    // import custom classes
    import com.main.BuildStageClass;
    import com.main.BootClass;
    import com.utils.RotateClass;
    import com.utils.ZoomClass;
    import com.utils.PanClass;
    import com.main.HotSpotClass;
    // initialize class
    public class DocClass extends MovieClip {
      // custom classes
      // variables
      public static var build_stage_class:BuildStageClass;
      public static var boot_class:BootClass;
      public static var rotate_class:RotateClass;
      public static var zoom_class:ZoomClass;
      public static var pan_class:PanClass;
      public static var hot_spot_class:HotSpotClass;
      // stage containers
      public static var main_stage:MovieClip;
      public static var background_layer:MovieClip;
      public static var content_layer:MovieClip;
      public static var popup_layer:MovieClip;
      // main constructor
      public function DocClass() {
       // initialize classes
       build_stage_class = new BuildStageClass();
       boot_class = new BootClass();
       rotate_class = new RotateClass();
       zoom_class = new ZoomClass();
       pan_class = new PanClass(this.stage);
       hot_spot_class = new HotSpotClass();
       // add containers to stage
       main_stage = new MovieClip();
       addChild(main_stage);
       background_layer = new MovieClip();
       main_stage.addChild(background_layer);
       content_layer = new MovieClip();
       main_stage.addChild(content_layer);
       popup_layer = new MovieClip();
       main_stage.addChild(popup_layer);
    ==========================
    Now inside the pan class:
    package com.utils{
    // import classes
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.ui.Mouse;
    // import main classes
    import com.DocClass;
    // initialize class
    public class PanClass extends MovieClip {
      // variables
      public var do_pan:Boolean = true;
      public var last_point:Number = 0;
      public var cur_point:Number = 0;
      public var hand_cursor:HandCursor;
      public var grab_cursor:PanCursor;
      private var myStage:Stage;
      // main constructor
      public function PanClass(docClassStage:Stage) {
       // constructor code
       myStage = docClassStage;
       myStage.addEventListener(MouseEvent.MOUSE_MOVE, panHandler);
    Ideas?

Maybe you are looking for

  • Ical year view

    hi ! i was wondering if someone has come up with a way of getting ical to show entire years. maybe a little help programm from the depths of the mac community ? thanks ! pia

  • My WD external hard drive is no longer show up on my computer-it no longer recognizes it.

    I have a WD external hard drive for sometime that I have been using to backup my computer and generally keep some of my bigger things on it(such as degital copies of movies). But suddenly one day my computer won't recognize my external hard drive whe

  • BSOD after installing Boot Camp 5 drivers on my MacBook Pro (13" mid 2012, non-retina)

    Basically what the post says. I go through the normal rounds of creating a bootable flash drive (i've tried ISO files from 7, 8, and 8.1 -- all 64 bit versions), downloading the drivers either off the website, or through the Boot Camp Assistant, then

  • Service apple mobile device failed to start, Verify privileges. What?

    After being prompted to upgrade my iTunes software, I clicked ok. The upgrade failed to complete the installation with "service apple mobile device failed to start, Verify privileges to start system services". notice. I am given the option to Abort,

  • Picture has noise after export to JPEG

    Hey guys, I am using Lightroom 5.2 64bit version on my windows. After I export my raw in to the jpeg it has noise. But in the develop module it hasn´t. Also it has got a little bit noise in the library, but it´s the same picture. Where is the sense?