How do I create an genericized instance of this class?

Hi, I'm having trouble creating a proper generic instance of this class that I wrote. The class type is cyclic dependant on itself.
public class MyClass<T extends MyClass<T>>
I can create an instance like this:
MyClass<?> class = new MyClass();But I would be mixing raw types and generic types.
Is there anyway to create a proper generic instance of MyClass?
Thanks a lot
-Cuppo

Ah thanks georgemc,
your solution will certainly work.
If i may ask your opinion of something...
MyClass is designed such that the type parameter should always be the same as the class itself. It's kinda a hack to get the subclass type from the superclass.
so a hierarchy looks something like this:
class MyClass<T extends MyClass<T> >
class SubClass<T extends SubClass<T>> extends MyClass<T>
class FinalSubClass extends SubClass<FinalSubClass>So ideally i would want something like:
MyClass m = new MyClass<MyClass>();
(which is not possible)
is there a way to get around this?
-Cuppo

Similar Messages

  • How do i create a single instance of a class inside a servlet ?

    how do i create a single instance of a class inside a servlet ?
    public void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException {
    // call a class here. this class should create only single instance, //though we know servlet are multithreaded. if, at any time 10 user comes //and access this servlet still there would one and only one instance of //that class.
    How do i make my class ? class is supposed to write some info to text file.

    i have a class MyClass. this class creates a thread.
    i just want to run MyClass only once in my servlet. i am afriad, if there are 10 users access this servlet ,then 10 Myclass instance wouldbe created. i just want to avoid this. i want to make only one instance of this class.
    How do i do ?
    they have this code in the link you provided.
    public class SingletonObject
      private SingletonObject()
        // no code req'd
      public static SingletonObject getSingletonObject()
        if (ref == null)
            // it's ok, we can call this constructor
            ref = new SingletonObject();          
        return ref;
      public Object clone()
         throws CloneNotSupportedException
        throw new CloneNotSupportedException();
        // that'll teach 'em
      private static SingletonObject ref;
    }i see, they are using clone !, i dont need this. do i ? shouldi delete that method ?
    where do i put my thread's run method in this snippet ?

  • How can i create a new instance on unix

    Hi,
    How can i create a new instance(instance only) on UNIX and how can i mount my database with this new instance.

    udayjampani wrote:
    Hi,
    How can i create a new instance(instance only) on UNIX and how can i mount my database with this new instance.1) Define Instance in your way!!?
    If you simply create a pfile and startup nomount with it, then -in theory- you have an instance running ( this method is used e.g. for restoring a rman backup )
    2) You can't. Database files are bound to a certain instance. What you can do is recreate an instance with e.g. a different name, using the scripts generated by a 'alter database backup controlfile to trace;' command
    Cheers
    FJFranken

  • How do I create a main instance?

    Hello,
    when I want to create an application component in the process scenario edtior I can choose a "main instance". However how do I create a main instance? I suppose that this has to be done in SLD but I found nothing there.
    When can a main instance and a product be different? I do not yet fully understand the concept behind it as both consist of several product component versions that can be installed on a technical system, right?
    Any explanation is highly appreciated. Thank you.

    Hi!
    I hope this makes things clearer:
    "A main instance is a group of technically interdependent software component versions, which are all installed and run on one server. A main instance represents the smallest non-divisible unit within a system landscape. An application component in a Process Integration scenario represents a system at configuration time and at runtime. Therefore, use main instances by default. This is because main instances represent the software component versions installed on a system. Only if a product comprises exactly one main instance may you also use a product version."
    Regards,
    Volker

  • Create a new instance of a class without starting new windows.

    I've a class with basic SWING functions that displays an interface. Within this class is a method which updates the status bar on the interface. I want to be able to reference this method from other classes in order to update the status bar. However, in order to do this, I seem to have to create a new instance of the class which contains the SWING code, and therefore it creates a new window.
    Can somebody give me an example, showing how I might update a component on the interface without a new window being created.
    Many thanks in advance for any help offererd.

    I've a class with basic SWING functions that displays
    an interface. Within this class is a method which
    updates the status bar on the interface. I want to be
    able to reference this method from other classes in
    order to update the status bar. However, in order to
    do this, I seem to have to create a new instance of
    the class which contains the SWING code, and
    therefore it creates a new window.
    Can somebody give me an example, showing how I might
    update a component on the interface without a new
    window being created.
    Many thanks in advance for any help offererd.It sounds like you have a class that extends JFrame or such like and your code must be going
               Blah  test = new Blah();
                test.showStatus("text");Whereas all you need is a reference to that Classs.
    So in your class with basic SWING functions that displays an interface.
    You Might have something like this
              // The Label for displaying Status messages on
              JLabel statusLabel = new JLabel();
              this.add( statusLabel , BorderLayout.SOUTH );What you want to do is provide other Classes a 'method' for changing your Status Label, so in that class you might do something like:
          Allow Setting of Text in A JLabel From various Threads.
         And of course other classes......
         The JLabel statusLabel is a member of this class.
         ie defined in this class.
        @param inText    the new Text to display
       public void setStatusText( String inText )
                    final String x = inText;
                    SwingUtilities.invokeLater( new Runnable()
                              public void run()
                                       statusLabel.setText( x );
      }You still need a reference to your first class in your second class though.
    So you might have something like this:
            private firstClass firstClassReference;        // Store Reference
            public secondClass(  firstClass  oneWindow )
                          // create whatever.........
                         this.firstClassReference = oneWindow;
    // blah blah.
          private someMethod()
                            firstClassReference.setStatusText( "Hello from Second Class");
        }Hope that gives you some ideas

  • [JS, CS4] TextFrame.extractLabel() cannot work with instances of this class

    I have script, which has been working fine in CS3. In CS4 ( app.version = 6.0.1.532 ) however, I get an error using extractLabel, after reading out a couple of other properties from a textframe:
    frameObject.extractLabel('name')
    Error: TextFrame.extractLabel() cannot work with instances of this class
    Up until reading one of the "normal" properties, such as (frameObject.)contents I can call the frameObject.extractLabel('name') without errors, but after "looking at" (by assigning to a variable in code, or by getting the value in the javascript console), the contents propery (or as it seems any normal property) the extractLabel method results in the error above.
    It seems to work to move all of the frameObject.extractLabel calls to the beginning of the function, but I don't think I should need to do that.
    It might very well be the case that the label read by extractLabel has no contents, and has never been assigned. Is there a change in behaviour from CS3 in that sentence? If so, and if thats the reason for the error, is there then a way to determine whether the label has ever been assigned?
    Is this error familiar to anyone else?
    Best regards,
    Andreas

    Hi Andreas,
    Interesting problem!
    Your problems are caused by some peculiarities of itemByID. itemByID doesn't cast the object type properly. Dirk wrote about some aspects of this some time ago. If the scripting engine was strongly typed, this issue would probably be impossible but that would make scripting a lot more of an elitist activity!
    Your problem is that the object type is PageItem and you are accessing a TextFrame property (content). This seems to throw the object type for a loop.
    Using getElements() causes the scripting engine to rebuild the reference to the object correctly.
    Take a look at this code, which illustrates the issue quite well...
    var myDocument = app.documents.add();
    myDocument = app.activeDocument;
    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
    var myTextFrame = myDocument.pages.item(0).textFrames.add({geometricBounds:[72, 72, 144, 288], contents:"test"});
    var myId = myTextFrame.id;
    var pgItm = myDocument.pageItems.itemByID(myId);
    alert(pgItm instanceof PageItem);
    alert(pgItm instanceof TextFrame);
    var thisBounds = pgItm.geometricBounds;
    var x = pgItm.extractLabel('mandatory');
    var pgItm = myDocument.textFrames.itemByID(myId);
    alert(pgItm instanceof PageItem);
    alert(pgItm instanceof TextFrame);
    var thisName = pgItm.extractLabel('name');
    var thisContents = pgItm.contents;
    var x = pgItm.extractLabel('mandatory');
    Harbs

  • How do I create a second instance of oc4j in a standalone enviroment

    I am using OC4J standalone to deploy a sparql endpoint using jena, joseki, and the oracle jena adaptor. OC4J is running on the same server as my DEV and QAR databases. The current instance of OC4J is using a data source called "OracleSemDS" to connect to my DEV database. We are now ready to migrate the endpoint to QAR. As I was setting up the QAR endpoint, I discovered the the jena/joseki tools are hard-coded to use the "OracleSemDS" data source. Therefore, I cannot have 2 endpoints running in the same OC4J instance where one points to DEV and the other points to QAR.
    Therefore, I need to create a second instance of OC4J that specifies QAR as the "OracleSemDS" data connection. Can someone tell me how to do that?
    Thanks,
    Phil

    jphilb wrote:
    I am using OC4J standalone to deploy a sparql endpoint using jena, joseki, and the oracle jena adaptor. OC4J is running on the same server as my DEV and QAR databases. The current instance of OC4J is using a data source called "OracleSemDS" to connect to my DEV database. We are now ready to migrate the endpoint to QAR. As I was setting up the QAR endpoint, I discovered the the jena/joseki tools are hard-coded to use the "OracleSemDS" data source. Therefore, I cannot have 2 endpoints running in the same OC4J instance where one points to DEV and the other points to QAR.
    Therefore, I need to create a second instance of OC4J that specifies QAR as the "OracleSemDS" data connection. Can someone tell me how to do that?
    Thanks,
    Philgday Phil -- Melli Annamalai from the Oracle Server PM team pointed me to your question. I was an OC4J Product Manager before we bought out BEA and I swapped over to WLS -- so I have some information below that hopefully is of assistance to you.
    Since you are using OC4J standalone, the simplest way to get a second instance, is to just clone the existing, whole directory structure of your working OC4J instance into another directory, and configure/run it from that directory. To map the OracleSemDS to another target (QAR) you change the data-sources.xml file in the second instance. If you want to run them concurrently on the same server, you'll need to change the ports in the second instance so they have unique values: default-web-site.xml, rmi.xml, internal-settings.xml, jms.xml. These additional ports can be specified on the command line as a Java property string, albeit this is not a documented nor supported feature. See http://buttso.blogspot.com/2007/02/specifying-oc4j-standalone-ports-from.html for more information.
    Now as an example, assuming you have your OC4J you want to clone in the dev directory, and now want to create a second instance of OC4J in qar, I'd do this:
    cp -rp dev/* qar
    cd qar/j2ee/home/config
    vi data-sources.xml
    (edit any other files if needed to alter ports) ...
    cd ..
    java -jar oc4j.jar That should work, and should create the second instance using the current configuration (ie dev) as its basis (including deployed apps). Of course, you'll need to manage them independently from here as they really are just two separate OC4J standalone instances.
    Now what else you could potentially do is to create a secondary configuration file subset only which only changes the necessary files to support running the second instance. In this case, you'd make a copy of the j2ee/home/config/server.xml, j2ee/home/config/application.xml and j2ee/home/config/data-sources.xml files, renaming them to qar-server.xml, qar-application.xml and qar-data-sources.xml.
    Then do the following:
    1. In qar-server.xml file, you'd change the global-application application to point at qar-application.xml instead of application.xml:
    <global-application name="default" path="qar-application.xml" parent="system" start="true" />
    2. Change qar-application.xml so that it used the qar-data-sources.xml file:
    <data-sources path="qar-data-sources.xml" />
    3. Change qar-data-sources.xml file so it points to the qar database target.
    4. Start OC4J, telling it to use qar-server.xml instead of the default server.xml
    D:\java\oc4j-10135-prod\j2ee\home>java -jar oc4j.jar -config config/qar-server.xmlI think you could run into some concurrency problems if you try and run the two instances simulataneously, but in general it should be OK I think if you run them separately.
    Another solution here is look at how the application specifies/uses datasources. The hard coding of the data-source name into the applicaiton via a direct JNDI lookup works, but restricts the flexibility you as a deployer/administrator has.
    If the application used the Java EE resource-ref approach to look up and use the datasource, then the actual JNDI name of the datasource the application uses it totally abstracted from the actual physical name of the datasource that is created on the container -- so you'd have DEVDS and QARDS as physical datasources configured and running on OC4J -- and what happens is that as you deploy the application, you essentially map its lookup and use of OracleSemDS (which would need to change to a java:env/ namespace) to the physical datasource you want it to use (DEVDS or QARDS for example). You can easily alter this post deployment by changing the generated orion-application.xml file to point at the alternate physical datasource. Following that, you can also create separate deployment plans which map the app to the different datasources, then feed this in with the deployment operation so that the correct mapping to either DEVDS or QARDS is done during the deployment process.
    I don't know what scope you have to change the application so the above may not be possible -- you'd need to change the lookup code so that it uses the Java EE reference model and change the meta-inf/application.xml to add the corresponding resource-ref entry which declares the logical datasource name that needs to be mapped on deployment.
    Another approach here may be to use an application embedded datasource, where you put a data-sources.xml file into the application archive itself (along with an orion-application.xml file which references it) whereupon at deployment time, a datasource specific to the application will be created. In this manner, you'd have say two copies of the same application to deploy (DEV, QAR) which contain different data-sources.xml file. From memory, each application will have its own JNDI namespace so their datasources can co-exist with the same names, with application level data-sources overriding server level ones. Since you'll most likely want to keep the same context-root for the web modules (which has to be unique per server) you'll generally need to run just one of the applications at a time. I'd do this like this: deploy one, stop it, deploy the other, stop it, then start only the one you need to test. In that way, you'll have one copy of the application running (either DEV or QAR) and one datasource definition running within it.
    Here's some documentation links to get you going:
    Managing Application Lifecycle (start, stop): http://download.oracle.com/docs/cd/E14101_01/doc.1013/e13978/adminclient.htm#BABHJAFE <-- describes admin_client.jar but general principles apply to ascontrol management of application.
    Packaging and Testing Applications: http://download.oracle.com/docs/cd/E14101_01/doc.1013/e13979/packag.htm#BHCFBEEC
    Application Level DataSources: http://download.oracle.com/docs/cd/E14101_01/doc.1013/e13975/datasrc.htm#CHDIBFHG
    Using Deployment Plans: http://download.oracle.com/docs/cd/E14101_01/doc.1013/e13980/deployplan.htm#CHDFEFAE
    cheers
    -steve-

  • How can I create a generic service by emcli

    Hi,
    I have a generic service associated with a simple jdbc test and wanna create similar items by emcli.
    I tried to create a generic service by
    emcli create_service -name="xxx" -type="generic_service" -availType="test" -availOp="or" -timezone_region="+1" -beacons="yyyy"
    But it return "Error:No key tests associated with target xxx"
    Can anyone help on this?
    Thanks.

    Hi,
    refer to the below How to document:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10b68b99-022e-2a10-999d-c4dc9ec24a59
    Assign points if useful
    Regards
    Venkata Devaraj

  • How to deal with the old instances of any class?

    Hi,
    I have a doubt regarding the old instances of any class. Currently i am designing a game in java swing. I have a new game button, which creates a new game instance of the game class. There might be conditions that the old game is finished and user has clicked for new game button. The old game instance is no more useful for me. In fact that old instance must be deleted from the memory and a new instance should reside in the memory until user again proceed for a new game.
    I want to ask that how to destroy old instances of any class?
    Thank you.

    rp0428 wrote:
    All you can do is remove any reference to it:
    myGame = null;If that was the last reference then it will be eligible for garbage collection and it MAY be collected.And note that there's rarely a good reason to do this. In most cases, simply letting things go out of scope when the method that uses them ends is sufficient. About the only time you need to explicitly set something to null like this is, for example, if you're implementing a collection class and you want to remove an entry.

  • Creating a new instance of a class within a superclass

    I have a class with 2 subclasses and in the top classs I have a method that needs to create a new instance of whihc ever class called it.
    Example:
    class Parent
         void method()
              addToQueue( new whatever type of event is calling this function )
    class Child1 extends Parent
    class Child2 extends Parent
    }What I mean is , if Child1 calls the method then a new Child1 gets added to the queue but if Child 2 calls method a new Child 2 gets added to the queue. Is this possible?
    Thanks.

    try
    void method()
    addToQueue(this.getClass().newInstance());
    }Is this what you want ?Won't that always add an object of type Parent?
    no if we invoke this method on the child object...
    we currently dun know how op going to implement the addToQueue()
    so... just making my guess this method will always add to same queue shared among
    Parent and it's childs......

  • How do I create a Skype Name in this new environme...

    For a variety of reasons, I have created a new Microsoft Account. In attempting to set it up with Skype, I was never asked to create a Skype Name. This has created issues sining into Skype, as well as telling people how to Skype me. I do NOT want to give them my email address as my Skype contact. A Skype name is much more suited for this situation.
    How do I create a Skype name that people can use to call me?
    This beggs the question of why Loging into Skype and idnetification is co complicated. Associated with this one account there are the following methods of primary identification: Skype Name, Microsoft Account, Display Name, Skype Community Name, and there seems to be an additional display name for each Skype accont in the Community which begins with live: and then a modified form of the user's email address. That is A LOT to remember. I had a difficult time just logging in because it asks for my Skype name and the blank would not accept any of the aforementioned identifications. I had to get here by signing into Skype Desktop and then clicking a link to go through rather than signing in. The sign in would not accept my credentials.
    Bottom line is all these issues would go away if I could figure out how to get a skype name.

    See this:
    http://community.skype.com/t5/Security-Privacy-Trust-and/New-to-Skype-and-having-trouble-signing-in/...

  • How do I create a script to do this?

    I have a photoshop file with several layers...about 100. I want to put each layers into it's own group. The name of the group must be the same as the name of the layer.
    I tried creating a action to do this but it did not work right. It only works for one layer selected individually. If I select multiple layers, then it forms nested groups.
    I was told that I can't do this using an action and I would need a script for this.
    How do I create this script?
    I am using adobe photoshop cs6 ( I think) , windows 7.

    This assumes that none of the layer are already in layerSets( group ) and none have layer locking.
    if(app.documents.length>0){
        var doc = app.activeDocument;
        while(!doc.artLayers[0].isBackgroundLayer && doc.artLayers.length>0  ){
            var newSet = doc.layerSets.add();
            newSet.name = doc.artLayers[0].name;
            doc.artLayers[0].move(newSet,ElementPlacement.INSIDE);

  • Generic instance maker and class definition in separate files - problem

    file: genericinstantiator.java
    package testGenericInstantiator;
    public final class GenericInstantiator {
         public <T> T makeInstance(Class<T> c) {
              T instance = null;
              try {
                   instance = c.newInstance();
              } catch (IllegalAccessException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (InstantiationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return instance;
    file: genericinstantiatorusage.java
    package testGenericInstantiator.usage;
    import testGenericInstantiator.GenericInstantiator;
    final class SillyClass {
         public void sayBoo() {
              System.out.println("boo");
    public final class GenericInstantiatorUsage {
         public static void main(String[] args) {
              GenericInstantiator gi = new GenericInstantiator();
              SillyClass sc = gi.makeInstance(SillyClass.class);
              sc.sayBoo();
              System.exit(0);
    thrown exception:
    java.lang.IllegalAccessException
    on the line 'instance = c.newInstance();' in instantiator
    reason in jdk:
    if the class or its nullary constructor is not accessible.
    question:
    how to avoid this? (in my situation, the place of making instance and its class MUST be separated in another files)
    Edited by: gizmo640 on Mar 27, 2008 11:39 AM

    package testGenericInstantiator;
    import java.lang.reflect.Constructor;
    import java.lang.reflect.InvocationTargetException;
    public final class GenericInstantiator {
         public <T> T makeInstance(Class<T> c) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
              T instance = null;     
              Class[] emptyParams = {};
              Constructor<T> con = c.getDeclaredConstructor(emptyParams);
              con.setAccessible(true);
              instance = con.newInstance();
              return instance;
    }setting constructor to accessible works well too

  • How to create a generic SP for this requirment

    Hi all,
    i have a requirment like .....i have 10 sp's (sp1,sp2,sp3.....sp10) in a package named as 'generic_pkg'.
    procedure sp1 (abc IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2);
    procedure sp2 (xyz IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2,
    sp_out2 OUT varchar2);
    procedure sp3 (pqr IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2,
    sp_out2 OUT varchar2,
    sp_out3 OUT varchar2);
    procedure sp10 (pqr IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2,
    sp_out2 OUT varchar2,
    sp_out3 OUT varchar2,
    sp_out4 OUT varchar2,
    sp_out5 OUT varchar2,
    sp_out6 OUT varchar2,
    sp_out7 OUT varchar2,
    sp_out8 OUT varchar2,
    sp_out9 OUT varchar2,
    sp_out10 OUT varchar2);
    now i want to create a new SP. the new sp is having input parameters as
    procedure new_sp (sp_name IN varchar2,
    parameter IN varchar2,
    sp_output OUT varchar2);
    now i will get sp name as input parameter and i have to check whether that sp is there on generic_pkg package or not.
    if sp found , then i have to call that sp and have to return output.
    the new_sp should be generic(i.e the new_sp should compatable to call any sp in the package 'generic_pkg'). my doubt is all the 10 sp's are having same inputs, but different no of outputs. How can i make new_sp as a generic sp?
    procedure new_sp (sp_name IN varchar2,
    parameter IN varchar2,
    sp_output OUT varchar2); ---- ? how to handle?
    please anybody can guid me with example....
    thanks in advance.....
    Edited by: user9041629 on Sep 7, 2010 6:01 AM

    Your 'requirement' of being able to submit a procedure name as parameter will result in using dynamic SQL all over the place.
    Consequently you violate the very reason why PL/SQL was invented: to diminish parsing
    I pray you don't have any customers who are going to buy this 'product'. They are not to be envied.
    I pray also you have a good lawyer.
    Sybrand Bakker
    Senior Oracle DBA

  • How can I create a generic listener?

    So I 'm coding a Flash animation where there are two streams
    of MovieClip objects scrolling both right to left on the top
    portion of the Stage and left to right on the bottom portion of the
    Stage. Each object is attached the Stage using attachMovie() and
    after they cross the Stage they are removed. I want to be able to
    attach some kind of listener to each object so they are can respond
    to onRollOver() and onPress(). Does anyone have any tips?
    Thanks,
    Mike

    you can add one listener to many movieclips, but that can't
    be used to define actions related to a movieclip that doesn't exist
    when the listener is created. you'd have to recreate the listener
    each time a movieclip is created/attached.
    why not define those handlers for movieclips as they are
    attached?

Maybe you are looking for

  • BAPIs to create sales orders for Returns and Debit Memo Request

    Hi, I have to create a sales order for document type Returns as well as a debit memo request.The BAPI 'BAPI_SALESORDER_CREATEFROMDAT2' is giving the following error message for Debit Memo Request document creation as well as for Returns. 761 Unpermit

  • Windows XP User Can't Log in to Password Protected iWeb Site

    Does anyone have advice for this problem? I have consistently been able to access my .Mac account from all PC browsers I can think of from my work computer (MSN, IE, Opera, Firefox). My mother-in-law uses a PC as well and she's had no trouble logging

  • Can't update Apple TV to 6.0

    I tried to update Applt TV but it says it is up to date with 5.3.  Should I even bother updateing with all these other problems I have been reading about?  Is this an apple software problem or did apple stop the update?

  • XML - comparison of to files

    Hi, I have 2 XML files with the same structure. How do I compare it? I found one on internet, http://www.deltaxml.com/core/ but it cost a lot. - Any free API ? - Any idea, any URL, special keyword to search for? -Aykut

  • 10g application server

    Although I posted this question yesterday under Apllication server subforum , I'll post it here also , becouse no one answered and maybe someone here knows. So, hi guys, We have 64 bit Xeon computer on which we installed 64 bit Win2003. Could you ple