Override method on an object construted by somebody

     customMenuComponent.addCustomLink(new CustomLinkComponenet("strlink","Storage Inbox",Index.class) {
               protected BookmarkablePageLink getBookmarkablePageLink() {
                    BookmarkablePageLink bookmarkablePageLink=   new BookmarkablePageLink("link",clazz){
                         protected void onBeforeRender() {
                              super.onBeforeRender();
                    return bookmarkablePageLink;
          customMenuComponent.addCustomLink(new CustomLinkComponenet("strlink","Storage Inbox",Index.class) {
               protected BookmarkablePageLink getBookmarkablePageLink() {
                    BookmarkablePageLink bookmarkablePageLink=   super.getBookmarkablePageLink(){
                         protected void onBeforeRender() {
                              super.onBeforeRender();
                    return bookmarkablePageLink;
          });the second block of code does not compile please explain me why and what is the workaround ? i can override a method on a object when I initialize with new but cannot override if I get the object from super or somebody constructs why ?

miro_connect wrote:
in my case is there way to copy object returned from super to object created in sub and override methods ?Perhaps. You need to know about the implementation of the original object.

Similar Messages

  • Overriding attributes in ABAP objects

    Hello,
    I currently want know if it is possible to override attributes in ABAP objects. i know it is possible with methods. I have extend a previous class functionality and want to change the refrence type of an attribute from the parent class, but only on the child. Is this possible in ABAP object or even in normal object oriented techniques.
    Thanks
    Brendan

    Hi,
    ususally you can achive this with other technics. You can e.g. use the class hierarchy for this:
    The attribute is of type REF_SUPERCLASS. Within the superclass it should be working when you set subclasses of REF_SUPERCLASS as attribute.
    Another way is to use interfaces as reference type for your attribute.
    Please refer to [ABAP Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/ce/b518b6513611d194a50000e8353423/frameset.htm]. Especially the chapters about Inheritance and Interfaces.
    Regards Rudi

  • What is happening overriding method  in JVM

    1.what is happeining in JVM while i do overriding method ?
    2. why we cant create object for abstract class. what is happeining in JVM?
    HOW TO I KNOW internal process of JVM above i mentioned . is there any book for this?

    There's plenty of information in the Java Virtual Machine specification available here on this web site.
    http://java.sun.com/docs/books/jvms/second_edition/html/Compiling.doc.html#14787
    regards,
    Owen

  • Some generic anonymous class overriding methods compile, while others don't

    I have the following (stripped-down) code. The abstract class SessionHandler<T> is used by other code to define and run an operation that needs a session to something. This is best done in my code with anonymous classes, because of the shear number of operations defined. In the EntityOps<T> class, these work great. But, in the last class shown here, SomeClass, the anonymous class definition fails, though the semantics are almost identical. (List<T> vs.List<AnotherClass>) What am I doing wrong here? Or is this a bug in Java?
    Thanks, Tom
    public interface IEntityOps<T> {
        T get();
        List<t> getAll();
    public abstract class SessionHandler<T> {
        abstract T handle(Session session) throws Throwable;
        public final T perform() {
            ... calls handle(session) ...
    // These anonymous class definitions compile fine!
    public class EntityOps<T> implements IEntityOps<T> {
        public T get() {
            T ret = null;
            ret = new SessionHandler<T>() {
                T handle(Session s) throws Throwable {
                    T ret = (some T object calculation);
                    return ret;
            }.perform();
            return ret;
        public List<T> getAll() {
            T ret = null;
            return new SessionHandler<List<T>>() {
                List<T> handle(Session s) throws Throwable {
                    List<T> ret = (some List<T> calculation);
                    return ret;
            }.perform();
    // This anonymous class definition fails with the error:
    // "SomeClass.java": <anonymous someMethod> is not abstract and does not override abstract method handle()
    //     in SessionHandler at line XX, column XX
    public class SomeClass {
        public List<AnotherClass> someMethod() throws {
            List<AnotherClass> ret = null;
            ret = new SessionHandler<List<AnotherClass>>() {
                List<AnotherClass> handle(Session s) throws Throwable {
                    List<AnotherClass> ret = (some List<AnotherClass> calculation);
                    return ret;
            }.perform();
            return ret;
    }

    I added @Override above the abstract method override, and it provides this additional error:
    "HousingConfigImpl.java": method does not override a method from its superclass at line 382, column 17
    I have also reconstructed the code layout in a separate set of classes that have no dependancies, but there's no error coming from these!
    public class CustomThing {
    public interface ISomeInterface<T> {
        List<T> interfaceMethod();
    public abstract class SomeAbstractClass<T> {
        private Class _c = null;
        public SomeAbstractClass(Class c) {
            _c = c;
        protected Class getC() {
            return _c;
        public abstract T methodToOverride(Object neededObject) throws Throwable;
        public final T finalMethod() {
            try {
                return methodToOverride(new Object());
            } catch(Throwable e) {
                throw new RuntimeException(e);
    import java.util.List;
    import java.util.Collections;
    public class SomeInterfaceImpl<T> implements ISomeInterface<T> {
        public List<T> interfaceMethod() {
            return new SomeAbstractClass<List<T>>(CustomThing.class) {
                public List<T> methodToOverride(Object neededObject) throws Throwable {
                    return Collections.emptyList();
            }.finalMethod();
    import java.util.Collections;
    import java.util.List;
    public class SomeOtherClass {
        public List<CustomThing> someMethod() {
            return new SomeAbstractClass<List<CustomThing>>(CustomThing.class) {
                public List<CustomThing> methodToOverride(Object neededObject) throws Throwable {
                    return Collections.emptyList();
            }.finalMethod();
    }So, there's something about my code that causes it to be, somehow, different enough from the example provided above so that I get the error. The only differences in the override method definitions in my actual code are in the return type, but those are different in the example above as well. Here are the class declarations, anonymous abstract class creation statements, and abstract method declarations from the actual code.
    public abstract class SessionHandler<T> {
        abstract T handle(Session session) throws Throwable;
    public class EntityOps<T> implements IEntityOps<T> {
                return new SessionHandler<List<T>>(_mgr, _c, "getAll" + _c.getName()) {
                    List<T> handle(Session s) throws Throwable {
    public class HousingConfigImpl implements IHousingConfigOperations, ISessionFactoryManager {
                ret = new SessionHandler<List<Tenant>>((ISessionFactoryManager)this, Housing.class, "getTenantsInNeighborhood") {
                    List<Housing> handle(Session s) throws Throwable {I can't for the life of me see any syntactical difference between my example and the real code. But, one works and the other doesn't.

  • Extending classes and overriding methods

    If I have a class which extends another, and overrides some methods, if I from a third class casts the extending class as the super class and calls one of the methods which gets overrided, is it the overrided method or the method of the superclass which get executed?
    Stig.

    Explicit cast can't enable the object to invoke super-class's method. Because dynamic binding is decided by the instance. The cast can just prevent you from using methods only defined in sub-class, but it does not let the object to use super-class's method, if the method's been overrided. Otherwise, the polymophism, which is one of the most beautiful feature of Object-Oriented thing, can't be achieved. As far as I know, the only way to use super-class's method is the super keyword in the sub-class, and seems no way for an object to do the same thing (I may wrong, since I haven't read the language spec).
    here's a small test:
    public class Test {
    public static void main(String[] args){
    A a = new B();
    a.method();
    ((A)a).method();
    class A{
    public void method(){
    System.out.println("A's method");
    class B extends A{
    public void method(){
    System.out.println("B's method");
    The output is:
    B's method
    B's method

  • What is the advantage of using methods to return objects?

    Hello there,
    What is the advantage of using static methods to return
    objects? Isnt this a Factory Pattern ?
    What is the real advantage of using methods to return objects
    rather than using public constructors to create objects ?
    Can some one please explain
    Regards

    I think there were two questions. The first (why
    static) is well answered but I hope somebody can
    answer the general question - why whatever =
    createSomething(); as opposed to whatever
    = new Something(); - because inquiring minds
    want to know.I thought I answered that question. Perhaps I need to be more specific.
    For the Singleton pattern, you don't want a new instance (except possibly the first time, if you're using lazy instantiation).
    For the Factory pattern, you might not always want an instance of the actual class containing the static methods, so new won't work.
    If, on the other hand, neither of the above holds, there is no reason not to use new (unless, of course, anyone can come up with another use of static creators).
    RObin

  • ER: Override Methods feature should detect anonymous inner class scope

    Hi,
    Given the following code:
    public class Class1 {
        public static void main(String[] args) {
            Thread t = new Thread() {
                // line 4
            t.start();
    }When the cursor is placed on line 4, activating the Override Method dialog (Source menu), should show Thread methods that I can override, in addition to Object methods. Currently only the method from class Object are being shown. The same treatment should also apply to local method inner classes. This happens with the latest 11g preview 3, and all previous versions.

    Hi,
    I'll file an ER
    Frank

  • Polymorphism & Overriding Methods

    Hello all,
    I'm creating a set of objects and trying to achieve polymorphism. However, I've run into some problems with the principles of overriding methods. My class structure is as follows (using pseudocode);
    BaseClass
    - Subclass1
    - Subclass2
    class BaseClass{
    abstract Object get();
    abstract void set(Object);
    class Subclass1 extends BaseClass{
    String get(){ return String; }
    void set(String){ this.String = String; }
    class Subclass2 extends BaseClass{
    Boolean get() { return Boolean; }
    void set(Boolean){ this.Boolean = Boolean; }
    The problem is that the subclasses are capable of setting and returning objects of different types. In order to get the polymorphic behavior I'm looking for, what do I need to do? Should I remove the abstract methods in the baseclass? Should I leave the abstract methods in the baseclass and change the methods in the subclasses?
    Please advise,
    R. Alcazar

    I think the following change will get you what you want:
    class BaseClass{
      abstract Object get();
      abstract void set(Object);
    class Subclass1 extends BaseClass{
      Object get(){ return String; }
      void set(Object){ this.String = (String)Object; }
    class Subclass2 extends BaseClass{
      Object get() { return Boolean; }
      void set(Object){ this.Boolean = (Boolean)Object; }
    }You may also want to check the class of the object in set to catch any errors.
    Jon
    Do you know of a Java job in Orange County, California?
    If so then please contact me: "http://home.pacbell.net/jswinth/Resume.htm"

  • Generically calling a method on an object

    Hello,
    I am trying to write a small utility method to generically call a method on an object.
    This is what I have.
        public static void doCall(Object o, String methodName, Object ... args){
            Class[] types = new Class[args.length];
            int i = 0;
            for(Object arg : args){
                types[i] = arg.getClass();
            try {
                Method m = o.getClass().getMethod(methodName, types);
                m.invoke(o, args);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Error dynamically calling method " + methodName + " on " + o.toString());
        }It doesn't work because it can't find the method. If I hard code the parameter types as "new Object[] {Double.TYPE}" it works fine (on methods that take a double).
    So, my question is, how can I generically set up the parameter types based on the types of the arguments?
    Thanks,
    ~Eric

    The problem is not on calling agr.getClass(), your primitive double is already autoboxed to a Double object. It is the doCall(...) method who expects an object, not a primitive. So when giving it a primitive value, java autoboxes it to the corresponding object type.
    This means your attempt will only work if the methods to call do not have any primitives as parameters.
    Test this code:
    public class GenericMethodCaller {
         public static void doCall(Object o, String methodName, Object ... args){
            Class[] types = new Class[args.length];
            int i = 0;
            for(Object arg : args){
                types[i++] = arg.getClass();
            try {
                Method m = o.getClass().getMethod(methodName, types);
                m.invoke(o, args);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Error dynamically calling method " + methodName + " on " + o.toString());
         public static void main(String[] args) {
              Callable callee = new Callable();
              callee.callabelMethod(10d);          
              GenericMethodCaller.doCall( callee, "callabelMethod", 10d ); // 10d gets autoboxed to a Double object.
    class Callable {
         public void callabelMethod(Double o) {
              System.out.println("callabelMethod(Double o) called");
         public void callabelMethod(double o) {
              System.out.println("callabelMethod(double o) called");
    }The output will be:
    callabelMethod(double o) called
    callabelMethod(Double o) called
    - Roy

  • How can I use methods of an object with private instantiation in my ABAP?

    Hello all,
    What is the work-around on using methods of an object marked as private instantiation? I tried to use concepts of <b>INHERITANCE</b> or <b>FRIENDS</b> of an object (<u>BCONTACT </u> in my case - a SAP standard object) but it did not work, or at least, I do not know how to properly code the statements in my ABAP program.
    Any code samples, other ideas?
    Your help is greatly appreciated.

    I am closing this question as there has been no answer.
    Message was edited by:
            Goharjou ardavan

  • How to use the index method for pathpoints object in illustrator through javascripts

    hii...
    am using Illustrator CS2 using javascripts...
    how to use the index method for pathpoints object in illustrator through javascripts..

    Hi, what are you trying to do with path points?
    CarlosCanto

  • Run-time error '1004' -- Method 'Container' of object '_Workbook' failed

    Dear All,
    One of our users is getting the following Microsoft Visual Basic error while running the report S_ALR_87013614.
    Run-time error '1004'
    Method 'Container' of object '_Workbook' failed.
    I have searched the forum posts for help. But I only found some details related to Run-time error 1004 related to some excel file security but not related to "Method 'Container' of object '_Workbook' failed".
    Could anyone please tell me how this error can be eliminated for the user?
    Regards,
    Lakshmi.

    Dear Arpan,
    We too observed a few PIDs along with the one that you have mentioned but they make no difference. Some users who has the PID G_RW_DOCUMENT_TYPE set with some value are getting the report.
    Upon further searching we are assuming that it could be an issue with the Microsoft applications or macro settings of the user. But not sure about it.
    Regards,
    Lakshmi Venigala.

  • When a Method Returns an Object, does it return a copy or a pointer?

    When you have a method that returns an Object, is the Object returning a copy of the Object returned inside
    of the Method or is it an Actual pointer to the Object inside of the method's coresponding Object?
    so say you have an object ...
    Class Something {
    JLabel myLabel = new JLable("myLabel");
    public JLabel getLabel() {
    return myLabel;;
    Something something = new Something();
    JLable theLabel = something.getLabel()
    theLable.setString("theLable");
    so when I setString on the Object theLabel , am I going to change the value of myLabel inside of the Object something?

    Yes, it returns a pointer.

  • Calling a method in BPM Object from jsp page

    hi all,
    I try to call a method from BPM Object using <f:invokeUrl >
    I change server side method properties to yes.
    and then how can i get request and response object inside the BPM method.
    Thanks.

    Thanks for ur response,
    But i mention about BPM method inside BPM Object.
    i found this inside the documentation.
    methodName(Fuego.Net.HttpRequest request, Fuego.Net.HttpResponse response)
    i need to match above BPM method and <f:invokeUrl > tag. am i right?
    But i don't know how to create method with argument "Fuego.Net.HttpRequest request, Fuego.Net.HttpResponse response" inside BPM Object.
    I can't find any place to define method argument inside Oracle BPM studio.
    I don't know how to parse argument like "Fuego.Net.HttpRequest request, Fuego.Net.HttpResponse response"
    With Regards,
    Wai Phyo
    Edited by: user8729650 on Sep 9, 2009 7:03 PM
    Edited by: user8729650 on Sep 9, 2009 9:20 PM

  • Calling a method in BPM Object from jsf page

    Hi All,
    How do I call a method in BPM object from JSF page? Is it possible to invoke it in a manner similar to invoking a method from managed bean in JSF application?
    Please help.
    Thanks and Regards,
    Veronica

    You can use f:invoke (or f:invokea to with parameters)
    For ajax calls, you can use f:invokeUrl to get the URL to a particular method within your BPM object, although make sure the Server-Side Method property is set to Yes.
    http://download.oracle.com/docs/cd/E13154_01/bpm/docs65/taglib/index.html

Maybe you are looking for