How do I redefine a Method of a Final Class?

Hi,
Is it possible to redefine a method of a final class and if so, can someone please give me a brief example of that technique?
Thank you very much!
Andy

Hi,
Please find the example.
Program Description :      Interface I1 contains two methods : M1 and M2.
I1 is included and incorporated in class : C1 with M2 as a final method. Both the methods are implemented in class C1.
Class C2 is a subclass of class C1. It redefines method : I1M1 and re-implements it, but it does not do that for I1M2 as that is declared as final method.
In the START-OF-SELECTION block, object OREF1 is created from class C1 and OREF2 from class C2 and both the methods M1 and M2 are called using both the objects.
Example:
report ytest .
interface i1 .
  methods : m1 ,
            m2 .
endinterface.
class c1 definition.
  public section.
   interfaces : I1 final methods m2 .
endclass.
class c1 implementation.
  method i1~m1.
   write:/5 'I am m1 in c1'.
  endmethod.
  method i1~m2.
   write:/5 'I am m2 in c1'.
  endmethod.
endclass.
class c2 definition inheriting from c1.
  public section.
   methods : i1~m1 redefinition .
endclass.
class c2 implementation.
  method : i1~m1.
   write:/5 'I am m1 in c2'.
  endmethod.
endclass.
start-of-selection.
  data : oref1 type ref to c1,
         oref2 type ref to c2 .
   create object : oref1 , oref2.
   call method  : oref1->i1~m1 , u201C Output : I am m1 in c1
                  oref2->i1~m1 , u201C Output : I am m1 in c2
                  oref1->i1~m2 , u201C Output : I am m2 in c1
                  oref2->i1~m2 . u201C Output : I am m2 in c1
Output :      I am m1 in c1 
I am m1 in c2 
I am m2 in c1 
I am m2 in c1 
Thanks,
Anitha

Similar Messages

  • How can I disable a method from a direved class

    I am extended TreeSet for an assigment with some new functionality.
    This new class is rbTree.
    I need to disable all of the old functions so that if a user creates a new rbTree he will only be able to use the methods defined in rbTree.
    rbTree uses some of treeSets methods using super.
    I now how to just overwrite them but I think I should let the user know those methods are unsupported, by throwing an exception. I can't throw any exceptions because most of treeSets methods don't.
    I know there is an easy way to do this, and I don't think I should just leave them blank.
    Any ideas?
    thanks in advance
    -Marc

    If you have a new class that extends TreeSet that shouldn't expose any of the TreeSet methods, don't extend TreeSet. Prefer composition over inheritance. You can use a TreeSet as a private member within your class; e.g. your new class has-a TreeSet, rather than is-a TreeSet. This way you control which functionality of the TreeSet to use, but only expose your new methods.
    Also, you should read and implement Code Conventions for the Java™ Programming Language - it will help you and others understand/maintain your code.
    Example:import java.util.TreeSet;
    public class RbTree
        private TreeSet set = new TreeSet();
         * only allow a specific type of object (my.pkg.MySpecialObject) to be added to the set.
        public add(MySpecialObject mso)
            set.add(mso);
        // other methods follow...
    }

  • Redefine a method

    Hi All,
    I am working on CRM 5.0 version. Can some one tell me the procedure as to how to redefine a method. I would want to redefine a method to add my custom functionality. I was searching for "Redefine" button but i dont get to see it. Can some one help?
    Thanks.

    Hi There,
    The redefine button is in the class builder under the methods tab and second from the right, it is a circle thing with a tool stuck to it. If there is no such button, you are likely looking at an interface, which has no implementation to redefine. If the button is greyed, you need to be in change mode.
    I'm assuming this is for the IC Webclient am I right? If so, be sure you are using the proper technique for enhancing the view - as outlined in the CRM 5.0 IC Web Client Consultant's Cookbook. It is not good practice to redefine the method of an SAP class if you can avoid it. Best is to derive a class from the SAP class, and then redefine the method in the derived class.
    Hope this helps.
    Sincerely,
    Glenn
    Glenn Abel
    Covington Creative
    www.covingtoncreative.com

  • How to access private method of an inner class using reflection.

    Can somebody tell me that how can i access private method of an inner class using reflection.
    There is a scenario like
    class A
    class B
    private fun() {
    now i want to use method fun() of an inner class inside third class i.e "class c".
    Can i use reflection in someway to access this private method fun() in class c.

    I suppose for unit tests, there could be cases when you need to access private methods that you don't want your real code to access.
    Reflection with inner classes can be tricky. I tried getting the constructor, but it kept failing until I saw that even though the default constructor is a no-arg, for inner classes that aren't static, apparently the constructor for the inner class itself takes an instance of the outer class as a param.
    So here's what it looks like:
            //list of inner classes, if any
            Class[] classlist = A.class.getDeclaredClasses();
            A outer = new A();
            try {
                for (int i =0; i < classlist.length; i++){
                    if (! classlist.getSimpleName().equals("B")){
    //skip other classes
    continue;
    //this is what I mention above.
    Constructor constr = classlist[i].getDeclaredConstructor(A.class);
    constr.setAccessible(true);
    Object inner = constr.newInstance(outer);
    Method meth = classlist[i].getDeclaredMethod("testMethod");
    meth.setAccessible(true);
    //the actual method call
    meth.invoke(inner);
    } catch (Exception e) {
    throw new RuntimeException(e);
    Good luck, and if you find yourself relying on this too much, it might mean a code redesign.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Calling a method in a different class?

    How do you call a method from a differnt class into the class you are working on?

    Class and method were just generic names. You should insert the names of your classes and methods.
    class OtherClass {
        public static void one() {
            System.out.println("Static method")l;
        public void two() {
            System.out.println("Non-static method");
    class MainClass {
        public static void main(String[] args) {
            OtherClass.one();
            OtherClass oc = new OtherClass();
            oc.two();
    }

  • Access DataControls methods in a java class

    Hi All,
    Jdeveloper Version 11.1.5
    I have created DataControls for SessionFacade web service.
    Inside the datacontrol there is a method getAllDepartments() which have a Return type which includes DaertmentId,DepartmentName,....
    I want to know how can i access this method inside a Java Class and create a list of only departmentId.

    You would need to add the method in the data control as a method action in your pageDef.
    After that, you could access the method as mentioned above.
    Thanks,
    Navaneeth

  • Overidding a method defined in a Final class via an interface.

    Hi,
    Is it possible to override methods of a final class
    which has implemented methods of an interface.
    interface A{
         void method1();     
    public final class FinalityA implements A{
         public void method1(){
              // Code
    }Now,I would like to override the functionality of
    method1() defined in class FinalityA.
    I cannot subclass FinalityA as this class is final.
    // Invalid.
    class Myclass extends FinalityA{
    }Is it possible to override the functionality defined in method1()
    Please suggest

    You can do:
    public class MyClass implements A {
       private final FinalityA _wrapee;
       public MyClass(FinalityA wrapped) {
           _wrapee = wrapped;
      public void method1() {
           .. do some special processing
          _wrapee.method1();
           .. do some more stuff
            }If you want to get really clever you can do stuff with java.lang.reflect.Proxy that allows you to automatically pass on calls to interface methods (this kind of thing is increasingly used for stuff like transaction management).
    What you can't do is to fiddle with the code of the method if called from a reference to FinalityA rather than a reference to the interface. The whole point of final classes and methods is to prevent that.

  • Final class: methods/fields automatically final?

    As a final class cannot be subclassed, methods/fields cannot be overwritten. But is there a performance/security difference between
    public final class A {
        public static final String S = "S";
        public final static do() {}
    }and
    public final class A {
        public static String S = "S";
        public static do() {}
    }?

    As a final class cannot be subclassed, methods/fields
    cannot be overwritten. But is there a
    performance/security difference betweenAll methods of a final class are implicitly final.
    Fields are not (you could demonstrate that very easily by altering the value of the field S in your example).

  • Redefining a method

    Is it possible to redefine a method of a class within an already instantiated instance of that class? For example if I have ...
    class Dog{
      public boolean isBigDog(int width, int height){
        return true;  // always says its a big dog
      public void sitOnCouch(){
         if(isBigDog(with,height){
           System.out.println("Dog can sit on the couch");
         }else{
           System.out.println("Dog CAN'T sit on the couch");
    public static void main(String[] args){
      Dog dog = new Dog();
      dog.sitOnCouch();  // prints out "Dog can sit on the couch"
      //now if I didn't want that same dog, not a new one, to sit on the couch how can I redefine isBigDog()
      //for that instance of dog?
    }What I am really trying to do is to redfine the isCellEditable(int row, int col) in the DefaultTableModel class on an already instantiated DefaultTableModel. User click's a check box to allow cells to be editable or not to be editable.

    AwhHawh.... GOT IT! In case anyone cares for this
    bit of code it will "change cell editable on the fly".Not bad at all. However it has the side effect of creating a whole new model and throwing away
    the old one. Let me suggest this instead, as per my previous post recommending a subclass:public class MyDefaultTableModel extends DefaultTableModel {
      // local variable to store "editable" status
      private boolean isEditable = true;
      public MyDefaultTableModel(Object[][] data, Object[] columnNames) {
        super(data, columnNames);
      public DefaultTableModel(Object[] columnNames, int rowCount) {
        super(columnNames, rowCount);
      // implement any other constructors you need like the above
      // method to change "editable" status
      public void setAllowEditing(boolean allow) {
        isEditable = allow;
      // override isCellEditable to use our private variable
      public boolean isCellEditable(int row, int column) {
        return isEditable;
    }Hope this helps.
    PC&#178;

  • How to call a specific method in a servlet from another servlet

    Hi peeps, this post is kinda linked to my other thread but more direct !!
    I need to call a method from another servlet and retrieve info/objects from that method and manipulate them in the originating servlet .... how can I do it ?
    Assume the originating servlet is called Control and the servlet/method I want to access is DAO/login.
    I can create an object of the DAO class, say newDAO, and access the login method by newDAO.login(username, password). Then how do I get the returned info from the DAO ??
    Can I use the RequestDispatcher to INCLUDE the call to the DAO class method "login" ???
    Cheers
    Kevin

    Thanks for the reply.
    So if I have a method in my DAO class called login() and I want to call it from my control servlet, what would the syntax be ?
    getrequestdispatcher.include(newDAO.login())
    where newDAO is an instance of the class DAO, would that be correct ?? I'd simply pass the request object as a parameter in the login method and to retrieve the results of login() the requestdispatcher.include method will return whatever I set as an attribute to the request object, do I have that right ?!!!!
    Kevin

  • How do I call an Application Module method from a EntityImpl class?

    Guys and Gals,
    Using Studio Edition Version 11.1.1.3.0.
    I've got a price update form, that when submitted, takes the part numbers and prices in the form and updates the corresponding Parts' price in the Parts table. Anytime this Parts view object's ReplacementPrice attribute is changed, an application module method needs to be called which updates a whole slew of related view objects. I know you can modify view objects via associations (How do I call an Application Module method from a ViewObjectImpl class? but that's not what I'm trying to do. These AppModuleImpl methods are the hub for all price updates, as many different operations may affect related pricing (base price lists, price buckets, etc) and hence, call the updatePartPricing(key) method.
    For some reason, the below code does not call / run / activate the application module's method. The AppModuleDataControl exists and recordPartHistory(key) is registered and public. At runtime, the am.<method> code is simply ignored, and as a weird side-effect, I cannot navigate out of my current page flow.
      public void setReplacementPrice(Number value)
        setAttributeInternal(REPLACEMENTPRICE, value);
        AppModuleImpl am = (AppModuleImpl)this.getDBTransaction().findApplicationModule("AppModuleDataControl");
        Key key = new Key(new Object[]
            { getPartNumber() });
        am.recordPartHistory(key);  // AppModuleImpl method which records pricing history
        am.updatePartPricing(key); // AppModuleImpl method which updates a whole slew of related pricing tables
      }Any ideas?

    Thanks Timo.
    Turns out the code provided was correct, but the AppModuleImpl method being called was not. A dependent ViewObject wasn't returning the row I was expecting. I then tried to perform some operations on that row, which in turn ... just stopped everything, but didn't give me an error.
    It was the lack of the error that threw me off. I had never messed with calling an AppModuleImpl method from the EntityImpl so I assumed that's what was messing up.
    You are correct. It is available from the ViewRow, but I thought it better to put it in the EntityImpl. This method will be called every time the replacement cost is modified. If I didn't put it in the EntityImpl, I'd have to remember to call it every time a replacement cost changed.

  • How can I invoke a method on a subclass based on the runtime type?

    Hi all,
    I have defined a base class OrderDetail, and 2 subclasses which extend it: OrderDetailSingleReservation and OrderDetailMonthReservation. Furthermore, I have a method:
        public Order order_generate(OrderDetail orderDetail) {
            if (orderDetail instanceof OrderDetailSingleReservation) {
                return order_generate((OrderDetailSingleReservation) orderDetail);
            }  else if (orderDetail instanceof OrderDetailMonthReservation) {
                return order_generate((OrderDetailMonthReservation) orderDetail);
            } else {
                Misc.alert("orderAndInvoice_Generate(GENERIC): unsupported type.");
                return null;
        }The type of this method's parameter is OrderDetail, as you can see. (This particular method only serves as a kind of dispatcher and is therefore not very interesting in itself, but the same pattern using 'instanceof' occurs in a codebase I am working on several times, and I would like to factor it out if possible.)
    My question: it seems that the invocation of order_generate() from within this method requires an explicit downcast to one of the two subclasses. If not, java invokes the method on the superclass. But at runtime, the JVM knows what type of object it is dealing with, right? So is there no way to do this without the explicit downcast?
    A similar problem occurs when trying to invoke a method on an object whose type is one of the subclasses; the method on superclass is called, instead of the one in the appropriate subclass that overrides it.
    Any help would be greatly appreciated!
    Thanks,
    Erik

    Thanks for your replies! I was editing my post last night to clarify it, but my connection went down and the edit was lost :(
    Anyway, yes, it should be done with polymorphism. I was constructing an example using the famous Animal, Cat and Dog classes to demonstrate my question more clearly, and to my surprise the problem does not occur in my example code.
    LRMK: Invoking a method such as in your example, where the method is inside the class itself, works fine. However for MVC's sake, I have a separate class called Invoicing with methods as below:
    class invoicing
      // the method for the superclass
      public Invoice invoice_create(OrderDetail orderDetail) {
         System.out.println("type: " + orderDetail.getClass());
         return null;
      // the method for one of the subclasses (this method is being not invoked)
      public Invoice invoice_create(OrderDetailSingleReservation orderDetail) {
         return null;
      // ...nor is this one.
      public Invoice invoice_create(OrderDetailMonthReservation od) {
         return null;
    }Now I attempt to invoke these methods:
    // create example objects
    OrderDetailSingleReservation odSingle = new OrderDetailSingleReservation();
    OrderDetailMonthReservation odMonth = new OrderDetailMonthReservation();
    // this call displays "odSingle type: OrderDetailSingleReservation"
    System.out.println("odSingle type: " + odSingle.getClass());
    // this call displays "odMonth type: OrderDetailMonthReservation"
    System.out.println("odMonth type: " + odMonth.getClass());
    // this call invokes Invoicing.invoice_create(OrderDetail)
    // instead of Invoicing.invoice_create(OrderDetailSingleReservation)
    Invoicing.invoice_create(odSingle);
    // this call invokes Invoicing.invoice_create(OrderDetail)
    // instead of Invoicing.invoice_create(OrderDetailMonthReservation)
    Invoicing.invoice_create(odMonth);So these calls will invoke the method for the superclass, i.e. Invoicing.invoice_create(OrderDetail od). That method then then executes the System.out.println() call which displays the class type of its parameter as one of { OrderDetailSingleReservation | OrderDetailMonthReservation }, that is, the expected subclass types!
    So the dynamic dispatch isn't working the way I would expect it to. If I do the explicit if-else checking using instanceof, as described in my first post, the correct methods are called.
    I hope the problem is somewhat clearer now. I am a bit lost as to what might be causing this, or how to monitor what's going on inside the jvm. Any ideas? BTW, the OrderDetail class and its subclasses are JPA entities (though I don't think it should matter).
    Thanks!
    Erik

  • How to override the create method invoked by a create form?

    Hello everyone, I'm using ADF Faces and have the next question:
    How can I override the create method which is invoked by a create form to preset an attribute in the new row (the preset value is not fixed, I have to send it to the method as a parameter as it is obtained using an EL expression)?
    In the ADF guide I read how to override a declarative method (Section 17.5.1 How to override a declarative method), but this explains how to do it with a method that is called by a button. I don't know how to do the same with a method which is called automatically when the page is loaded.
    I also tried overriding the view object's createRow() method to receive a parameter with the preset values but it didn't work, I believe that was because the declarative create method is not the same as the view object's createRow. This caused the form to display another row from the viewobject and not the newly created one (I also set the new row into STATUS_INITIALIZED after setting the attribute).
    Well, I hope my problem is clear enough for somebody to help me.
    Thank you!

    Hello,
    I'm not sure you can do it with standard generated Create Form.
    In your view object you'll need to create your own create method with parameters, publish it to client interface and invoke instead of standard generated create action in page definition.
    Rado

  • 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

  • How to use the POST method In Oracle APEX 3.1

    Hi,
    In APEX if we are submitting the page the parameters( Variables ) will pass through URL.
    How to hide the these parameters from URL??
    I Hope POST method will solve this problem.
    How to use the POST method in APEX???
    Help me out to solve this problem.
    thanks in advance.
    Cheers,
    Shan

    In APEX if we are submitting the page the parameters( Variables ) will pass through URL.No they won't. Submission POSTs the <tt>wwv_flow</tt> form.
    Sometimes a branch may be performed after submission, generating a URL in which parameter values are visible. To avoid this, use the save state before branching option.
    Other actions&mdash;like using navigation lists, or clicking a link in a report&mdash;will perform a GET using parameters in the URL. In these cases using Session State Protection is advised.

Maybe you are looking for

  • Group Headers are not getting displayed in crystal report

    Hi, I have got 1 reprot having 8 subreports in it. In the parent report I group by 2 different fields. I have created 8 diff. sections under 2nd group and put every subreport in different section. The data in subreport gets displayed depending on the

  • Making a Swf a valid widget

    I have a swf carousel that will work sat inside an HTML file for the purposes of siting on a web page. What as3 code do I need to make this a valid widget? I don't actually need it to interact with the captivate project, but I need the user to be abl

  • Block internal batch number at plant level

    Dear Experts, I have activated the internal batch number assignments at client level. But for some plants or one of the company code, I want to block the internal batch number creation during the goods receipt at production order confirmation(CO11N).

  • APN Edit for unlocked Phone

    I have unlocked iphone 4 and using it over Vodafone egypt , and i am not able to edit the APN , i got unlocked to manage as i want . can any body help in this issue

  • Have you ever see such error in service desk crmd_order ?

    Start of processing 'Individual receipt'