String equal method Vs Object equal method.

hello, Can anybody explain me difference between equal method in String class and equal method in Object class. We have equal method in object classes. and object class is the super class of all classes, so why we need equal method in String class.

RGEO wrote:
hello, Can anybody explain me difference between equal method in String class and equal method in Object class. We have equal method in object classes. and object class is the super class of all classes, so why we need equal method in String class.Because "equal" means different things for different objects. For a String, "equal" would mean that both Strings being compared have the exact same characters, in the same sequence. For an Integer, "equals" would mean that both objects have the same integer value.

Similar Messages

  • String Object equals method question

    What is the difference between these two lines of code:
         boolean ok = myString.equals(�foo�);
         boolean ok = �foo�.equals(myString);

    If myString is null, the first one will throw a NullPointerException, whereas the second one will just evaluate to false.
    If you know myString won't be null, I find the first one more natural looking, but that may just be personal preference.
    If there's a chance that myString could be null, and it's valid for it to be null and you just want to handle that like any other unequal case, then the second one saves you an explicit null test, since String's equals method does it ayway.
    String str = null;
    str.equals("foo"); // #1
    "foo".equals(str); // #2 Do you understand why #1 throws NullPointer exception and why #2 does not?

  • Difference between Object equals() method and ==

    Hi,
    Any one help me to clarify my confusion.
    stud s=new stud();
    stud s1=new stud();
    System.out.println("Equals======>"+s.equals(s1));
    System.out.println("== --------->"+(s==s1));
    Result:
    Equals ======> false
    == ------------> false
    Can you please explain what is the difference between equals method in Object class and == operator.
    In which situation we use Object equals() method and == operator.
    Regards,
    Saravanan.K

    corlettk wrote:
    I'm not sure, but I suspect that the later Java compilers might actually generate the same byte code for both versions, i.e. I suspect the compiler has gotten smart enough to devine that && other!=null is a no-op and ignore it... Please could could someone who understands bytecode confirm or repudiate my guess?Don't need deep understanding of bytecode
    Without !=null
    C:>javap -v SomeClass
    Compiled from "SomeClass.java"
    class SomeClass extends java.lang.Object
      SourceFile: "SomeClass.java"
      minor version: 0
      major version: 49
      Constant pool:
    const #1 = Method       #4.#15; //  java/lang/Object."<init>":()V
    const #2 = class        #16;    //  SomeClass
    const #3 = Field        #2.#17; //  SomeClass.field:Ljava/lang/Object;
    const #4 = class        #18;    //  java/lang/Object
    const #5 = Asciz        field;
    const #6 = Asciz        Ljava/lang/Object;;
    const #7 = Asciz        <init>;
    const #8 = Asciz        ()V;
    const #9 = Asciz        Code;
    const #10 = Asciz       LineNumberTable;
    const #11 = Asciz       equals;
    const #12 = Asciz       (Ljava/lang/Object;)Z;
    const #13 = Asciz       SourceFile;
    const #14 = Asciz       SomeClass.java;
    const #15 = NameAndType #7:#8;//  "<init>":()V
    const #16 = Asciz       SomeClass;
    const #17 = NameAndType #5:#6;//  field:Ljava/lang/Object;
    const #18 = Asciz       java/lang/Object;
    SomeClass();
      Code:
       Stack=1, Locals=1, Args_size=1
       0:   aload_0
       1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
       4:   return
      LineNumberTable:
       line 1: 0
    public boolean equals(java.lang.Object);
      Code:
       Stack=2, Locals=2, Args_size=2
       0:   aload_1
       1:   instanceof      #2; //class SomeClass
       4:   ifeq    25
       7:   aload_1
       8:   checkcast       #2; //class SomeClass
       11:  getfield        #3; //Field field:Ljava/lang/Object;
       14:  aload_0
       15:  getfield        #3; //Field field:Ljava/lang/Object;
       18:  if_acmpne       25
       21:  iconst_1
       22:  goto    26
       25:  iconst_0
       26:  ireturn
      LineNumberTable:
       line 6: 0
    }With !=null
    C:>javap -v SomeClass
    Compiled from "SomeClass.java"
    class SomeClass extends java.lang.Object
      SourceFile: "SomeClass.java"
      minor version: 0
      major version: 49
      Constant pool:
    const #1 = Method       #4.#15; //  java/lang/Object."<init>":()V
    const #2 = class        #16;    //  SomeClass
    const #3 = Field        #2.#17; //  SomeClass.field:Ljava/lang/Object;
    const #4 = class        #18;    //  java/lang/Object
    const #5 = Asciz        field;
    const #6 = Asciz        Ljava/lang/Object;;
    const #7 = Asciz        <init>;
    const #8 = Asciz        ()V;
    const #9 = Asciz        Code;
    const #10 = Asciz       LineNumberTable;
    const #11 = Asciz       equals;
    const #12 = Asciz       (Ljava/lang/Object;)Z;
    const #13 = Asciz       SourceFile;
    const #14 = Asciz       SomeClass.java;
    const #15 = NameAndType #7:#8;//  "<init>":()V
    const #16 = Asciz       SomeClass;
    const #17 = NameAndType #5:#6;//  field:Ljava/lang/Object;
    const #18 = Asciz       java/lang/Object;
    SomeClass();
      Code:
       Stack=1, Locals=1, Args_size=1
       0:   aload_0
       1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
       4:   return
      LineNumberTable:
       line 1: 0
    public boolean equals(java.lang.Object);
      Code:
       Stack=2, Locals=2, Args_size=2
       0:   aload_1
       1:   instanceof      #2; //class SomeClass
       4:   ifeq    29
       7:   aload_1
       8:   ifnull  29
       11:  aload_1
       12:  checkcast       #2; //class SomeClass
       15:  getfield        #3; //Field field:Ljava/lang/Object;
       18:  aload_0
       19:  getfield        #3; //Field field:Ljava/lang/Object;
       22:  if_acmpne       29
       25:  iconst_1
       26:  goto    30
       29:  iconst_0
       30:  ireturn
      LineNumberTable:
       line 6: 0
    }

  • POF object equals() method

    Hi there,
    I have got a compound key that represented with Java object that has three member fields. One of the fields should not be part of the key, so it should not be used when two keys are compared.
    This logic is defined in equals function
         public boolean equals(Object that) {
              CacheFactory.log("Hello from equals: " + this.toString());
              boolean result = false;
              if (this == that) {
                   result = true;
              } else {
                   if (that == null)
                        result = false;
                   else{
                        if (!(that instanceof KeyObject)) {
                             result = false;
                        } else {
                             KeyObject other = (KeyObject) that;
                             if (this.field1.equalsIgnoreCase(other. field1)
                                       && ( (this. field2.equalsIgnoreCase(other. Field2))))
                                  result = true;
                             else
                                  result = false;                    
              CacheFactory.err("Equals result is " + result);
              return result;
    Then I put on Coherence object with the following key {“field1_value”, “field2_value”, “field3_value”}. Then I am removing object from Coherence with the following key {“field1_value”, “field2_value”, “field3__another_value”}.
    According to the defined equals() function, those two keys are equal, but object is not getting removed. To remove it, I had to make all fields equal, even field3.
    Another thing – I do not see any logging from equals() function – I am using CacheFactory.log() to write log entry. Look in all logs files and could not find them – where I should be looking for them or what I should be using for logging from equals() function?

    Hi
    Yes you are correct and this is due to the fact that Coherence will first serialize your Key into a Binary. Which have a slightly more optimized .equals() implementation. Since the Binary is a result of the serialization if you serialize all three fields all three fields will be used for the comparison.
    If you really would like the remove the entries based upon two of the fields in the key I'd suggest a EntryProcessor combined with an
    Filter filter = new AndFilter(new EqualsFilter(new PofExtractor(String.class, ID_1), “field1_value”) , new EqualsFilter(new PofExtractor(String.class, ID_2), “field2_value”))
    This should match all entries with keys that where the first index (ID_1) == "field1_value" and the second index (ID_2) == “field2_value”.
    the you'd execute this filter inside your cache to remove the entries by
    cache.invokeAll(filter, new ConditionalRemove(AlwaysFilter.INSTANCE));
    Hope it helps
    /Charlie

  • While trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'

    Hi,
    Our PI is getting data from WebSphere MQ and pushing to SAP. So our sender CC is JMS and receiver is Proxy. Our PI version is 7.31.
    Our connectivity between the MQ is success but getting the following error while trying to read the payload.
    Text: TxManagerFilter received an error:
    [EXCEPTION]
    java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'
           at com.sap.aii.adapter.jms.core.channel.filter.ConvertJmsMessageToBinaryFilter.filter(ConvertJmsMessageToBinaryFilter.java:73)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
           at com.sap.aii.adapter.jms.core.channel.filter.InboundDuplicateCheckFilter.filter(InboundDuplicateCheckFilter.java:348)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
    I have searched SDN but couldn't fix it. Please provide your suggestion.
    With Regards
    Amarnath M

    Hi Amarnath,
    Where exactly you are getting this error?
    If you are getting at JMS Sender communication channel, try to stop and start the JMS communication channel and see the status, also use XPI Inspector to get the exact error log.
    for reference follow below blogs:
    Michal's PI tips: ActiveMQ - JMS - topics with SAP PI 7.3
    Michal's PI tips: XPI inspector - help OSS and yourself
    XPI Inspector

  • Approval task SP09: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'

    Hi everyone,
    I just installed SP09 and i was testing the solution. And I found a problem with the approvals tasks.
    I configured a simple ROLE approval task for validate add event. And when the runtime executes the task, the dispatcher log shows a error:
    ERROR: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'
    And the notifications configured on approval task does not start either.
    The approval goes to the ToDO tab of the approver, but when approved, also the ROLE stays in "Pending" State.
    I downgraded the Runtime components to SP08 to test, and the approvals tasks works correctly.
    Has anyone passed trough this situation in SP09?
    I think there is an issue with the runtime components delivered with this initial package of SP09.
    Suggestions?

    Hi Kelvin,2016081
    The issue is caused by a program error in the Dispatcher component. A fix will be provided in Identity Management SP9 Patch 2 for the Runtime component. I expect the patch will be delivered within a week or two.
    For more info about the issue and the patch please refer to SAPNote 2016081.
    @Michael Penn - I might be able to assist if you provide the ticket number
    Cheers,
    Kristiyan
    IdM Development

  • Implementing the CompareTo(Object T) method of interface Comparable T

    Hi,
    I cannot figure out how to write implementation to compare two objects for the CompareTo method.
    I have an Employee class and a Manager class that inherits Employee and in the main method i want to sort the objects so that i can use the method binarySearch(Object[] a, Object key), originally i sorted each object in order of their salaries but i now need to be able to distinguish between a Manager object and an Employee object.

    demo:
    class Base implements Comparable<Base> {
        private String baseField;
        @Override public int compareTo(Base that) {
            return this.baseField.compareTo(that.baseField);
    class Derived extends Base {
        private String derivedField;
        @Override public int compareTo(Base that) {
            int result = super.compareTo(that);
            if (result == 0 && that instanceof Derived) {
                Derived thatThang = (Derived) that;
                result = this.derivedField.compareTo(thatThang.derivedField);
            return result;
    }Base objects are ordered by baseField. (I assume all fields will be non-null, for simplicity.) Between Derived objects with equal baseField, I order them further by derivedField.
    edit. I should mention that there are headaches that usually follow when you compare objects of different types. Suppose you have three objects:
    obj1, a Derived object with baseField = "b", derivedField = "x"
    obj2, a Base object with baseField = "b"
    obj3, a Derived object with baseField = "b", derivedField = "y"
    according to the compareTo methods, obj1 and obj2 are equal, and as well, obj2 and obj3 are equal, but obj1 and obj3 are not equal, so we do not have transitivity. ;-(

  • Question about "java.lang.Object.equals()".

    public class TestEquals {
      private int a;
      private int b;
      public TestEquals(int a,int b) {
        setA(a);
        setB(b);
      public int getA() {
        return a;
      public void setA(int a) {
        this.a = a;
      public int getB() {
        return b;
      public void setB(int b) {
        this.b = b;
      public static void main(String[] args) {
        TestEquals te01 = new TestEquals(1,2);
        TestEquals te02 = new TestEquals(1,2);
        System.out.println("te01 equals to te02: " + te01.equals(te02));
        te01.setA(2);
        System.out.println("te01 equals to te02: " + te01.equals(te02));
    }The result is:
    te01 equals to te02: false
    te01 equals to te02: false
    Why the first case is false?

    You didn't override Object.equals() in your TestEquals class. So, you are calling Object.equals(), which just compares reference values. You need to write your own equals() method (presumably, make sure te01.a==te02.a and te01.b==te02.b). Depending on what you do with your objects, you would want to override Object.hashCode(), too.

  • Vectors: contains() inconsistency with Object equals()

    Hi,
    I have a problem with using Vector contains() on my own classes.
    I have a class TermDetails, on which I have overloaded the equals() method:
         public boolean equals(Object other) {
              try {
                   TermDetails otherTerm = (TermDetails) other;
                   return (term.equals(otherTerm.term));
              catch (Exception e) {
                   try {
                        String otherTermString = (String) other;
                        return (term.equals(otherTermString));
                   catch (Exception f) {
                        System.out.println("Can't convert Object to TermDetails or String");
                        System.out.println(f.getMessage());
                        return(false);
         public boolean equals(String otherTermString) {
              return(term.equals(otherTermString));
    The Vector.contains() should then use one of these equals methods to return correctly, but doesn't use either of them... any ideas why not?
    (I've tried adding some console output in the equals methods, just to prove if they get called or not. They don't.)
    Thanks in advance!
    Ed

    This won't work. It only tests whether the two objects are of the same class. In general, you need to test a number of things:
    1) if obj == this, return true
    2) if obj == null, return false
    3) if obj.getClass() != this.getClass() return false
    (Note: You don't need getClass().getName(). Also, there are times when the classes don't have to match, but it's sufficient that obj and this implement a particular interface--Map for instance).
    4) if all relevant corresponding fields of obj and this are equal, return true, else false.
    That's just a high level run-down, and you should definitely look at the book that schapel mentioned.
    Also, this probably won't affect Vector.contains, but make sure that when you override equals, you also override hashCode. The rule is that if a.equals(b) returns true, then a.hashCode() must return the same value as b.hashCode(). Basically any field that is used in computing hashCode must also be used in equals.
    Note that the converse is not true. That is two objects with the same hashCode don't have to be equal.
    For instance, if you've got a class that represents contact info, the hashCode could use only the phoneNumber field. hashCode will then be fast to compute, will probably have a good distribution (some distinct people's contact info could have the same phone number, but there won't be a large overlap), and then you use phone number plus the rest of the fields (address, etc.) for equals.
    Here's an example that shows that equals will work if
    written correctly
    import java.util.Vector;
    public class testEquals {
    public static void main(String args[]) {
    Vector testVector = new Vector();
    testVector.add(new A());
    testVector.add(new B());
    System.out.println("A == A? " +
    + testVector.contains(new A()));
    System.out.println("B == B? " +
    + testVector.contains(new B()));
    class A {
    public boolean equals(Object object) {
    if (getClass().getName() ==
    = object.getClass().getName()) {
    System.out.println("A == A");
    return true;
    } else {
    return false;
    class B {
    public boolean equals(Object object) {
    if (getClass().getName() ==
    = object.getClass().getName()) {
    System.out.println("B == B");
    return true;
    } else {
    return false;

  • Object.equals() question.

    Lets say i have a class:
    public class MyClass{
    int x;
    int y;
    int z;
    }And i have two objects: one and two...
    will
    one.equals(two)return true if the fields for both objects hold the same values?
    or return true if they both point to the exact same object?
    Edited by: JamesBarnes on Oct 8, 2008 12:34 PM

    hmm ok, how about this:
    i went to add my own equals method to my class:
    public class Block{
    private int x;
    public boolean equals(Block block){
    if this.x == block.getX(); // <-- Problem
    public int getX(){
    return x;
    }You can probably see what is going on here, i want to pas the equals method an object of type Block, but because the equals method is within Block it would seem that the method block.getX() cannot be used.
    Bizzarrely (im using net beans) although the fields are all private access i can see the fields of the passed "Block block" but not the methods that belong to block.
    I can sort of see the problem, calling accessor methods from within a block, its sort of like delving into it's self, but i cant see how else to check for similar objects.
    I hope i have made the problem clear,
    J

  • Nested object equality - design pattern

    Looking to solve a problem in my own code, I wanted to see if and how the problem is solved in the java library.
    I would have liked this code to output "true", to see how it's done.
    Set set1 = new HashSet();
    set1.add("a value");
    set1.add(set1);
    Set set2 = new HashSet();
    set2.add("a value");
    set2.add(set2);
    System.out.println(set1.equals(set2));Well the code ends with a StackOverflowError on hashCode(). Just using a Set which implements hashCode to return a constant value would shift the problem to the equals-method.
    I think one possible solution would be to implement the hashCode method to set a instance variable (computingHash = true) while hashcodes of fields are computed. If the variable is set when hashcode is invoke a RecursiveHashRuntimeException is thrown which is is caught by the invoking hashcode method which would then return a constant value or ignore the corresponding field for hash-computation.
    Similarly the equals method would add the obj (passed to equals) to a set (instance variable) named assumeEqualTo, if the obj is in assumeEqualTo when the method is invoked it returns true. The value is removed from assumeEqualTo before the method that added it returns.
    This approach would require the equals and hashcode methods to be - at least partially - synchronized (if multithreading is an issue), an alternative would be to use ThreadLocal variables to detect and handle recursive invocations.
    I'm not sure how the two approaches compare in terms of performance, and I would welcome any other approach to solve the problem. Note that the class being compared should not be required to know details about the contained classes and the nesting may also be indirect as in:
    Set set1 = new HashSet();
    Set set2 = new HashSet();
    set1.add("a value");
    set1.add(set2);
    set2.add("a value");
    set2.add(set1);
    System.out.println(set1.equals(set2));Also it would be nice if the impact on performance could be kept minimal for all instance that happens not to be self-containg.
    cheers,
    reto

    should be slightly different as for sets the orderis
    irrelevant
    I don't follow. You would presumably only return
    true as a whole if every element in the Set also
    returned true. So, yes, order is irrelevant. just wanted to say that you must return true iff you find a mapping from set1 to set2 where all elements are equals
    No, I mean that if you add a Set to itself, and then
    iterate over it, you will implicitly be performing
    recursion, leading to a StackOverflowError
    eventually. That is why you need to store a
    collection (or array) with all the objects already
    analyzed. What do you mean by "already analyzed"? I mean how would you prevent recursion with this?
    You need to compare what is being
    currently being inspected along with checking what
    you already processed for object equality (==) so you
    do not get the stack overflow.I don't get it, in
    Set set1 = new HashSet();
    Set set2 = new HashSet();
    set1.add(set2);
    set2.add(set1);
    set1.equals(set2);The equals method returns true iff set2.equals(set1), which would - in the algorithm I proposed - return set1.add(set2) which is true as set2 is contained in the Set assumeEqualTo. I interpreted the contract specified by java.util.Set to return true on equals for indistinguishable object - not sure if this is correct for mutually referencing sets, but pretty convinced for non-refrencing self containing sets, as in my first example or for all sets returned by:
    createSet() {
      Set s1 = new HashSet();
      Set s2 = new HashSet();
      s2.add(s1);
      s1.add(s2);
    }Imho, it would break be against the specification in java.util.Set to return false on createSet().equals(createSet()).
    reto

  • Interfaces and methods of Object class

    JSL 2.0 states the following
    If an interface has no direct superinterfaces, then the interface implicitly
    declares a public abstract member method m with signature s, return type r,
    and throws clause t corresponding to each public instance method m with
    signature s, return type r, and throws clause t declared in Object, unless a
    method with the same signature, same return type, and a compatible throws
    clause is explicitly declared by the interface.
    But the following codes produces empty output
    package test;
    import java.lang.reflect.Method;
    public class TestIterface {
        public static void main(String [] args){
            Method [] methods=Y.class.getMethods();
            for(int i=0, n=methods.length;i<n;i++)
                System.out.println(methods);
    interface Y{
    What are the reasons of such behaviour?

    then the interface implicitly declares a public abstract member method
    "Implicit" means that it's implied that the interface declares those methods; unlike java.lang.Object, there is no interface from which all other interfaces descend. All interfaces at the "top" of the inheritance hierarchy are implied to expose at least the same methods as Object.
    Hope this helps...

  • Method '~' of object '~' failed in Offline Planning

    Hi,
    When the members in a dimension are set to '~' in Essbase, Offline Planning will prompt an error "Method '~' of object '~' failed" when we try to select that dimension as page members. Is there a way to overcome this problem?
    Thanks in advance.

    Hi Caillen,
    1. It hapen to any user randomly. It is not for perticuler user/users.
    2. Error is thrown at server side.
    3. Below is the code shown in the error desciption.
    Public Sub ActiveBookmarkSet(iIndex As Integer, Optional szBookmark As String = "")
        On Error GoTo ActiveBookmarkSetErr
        Dim iErrorTimes As Integer
        iErrorTimes = 0
        If Not moBookmarks Is Nothing Then
            If iIndex > 0 Then
                If miActiveBookmarkCount >= iIndex Then
                    Set moBookmark = moBookmarks.Item(iIndex)
                    mszActiveBookmark = moBookmark
                End If
            ElseIf szBookmark <> "" Then
                If moBookmarks.Exists(szBookmark) = True Then
                    Set moBookmark = moBookmarks.Item(szBookmark)
                    mszActiveBookmark = moBookmark
                End If
            End If
        Else
            mobjRevision.objError.RaiseError CWORDERR_BASE_NoActiveBookmarks, App.EXEName & "::CGCDocWordApp::ActiveBookmarkSet", ""
        End If
        Exit Sub
    ActiveBookmarkSetErr:
        iErrorTimes = iErrorTimes + 1
        If iErrorTimes < 6 Then
            Resume
        End If
        Call mobjRevision.objError.RaiseError(Err, App.EXEName & "::CGCDocWordApp:ActiveBookmarkSet Method", Err.Description)
    End Sub

  • In macro call method of object

    Hi,
    is it possible to call method provides in parameter to macro ?
    From the call of my macro i provide object instancied and the name of my method. In my macro i wanted to do : CALL METHOD &1->&2 but it don't work.
    I provided you my code which does not function :
    REPORT  z_erca_test.
          CLASS lcl_ee_data DEFINITION
    CLASS lcl_ee_data DEFINITION.
      PUBLIC SECTION.
        METHODS:
          get_data_list,
          get_data_list_suisse.
    ENDCLASS.                    "lcl_ee_data DEFINITION
          CLASS lcl_ee_data IMPLEMENTATION
    CLASS lcl_ee_data IMPLEMENTATION.
      METHOD get_data_list.
        WRITE 'Default'.
      ENDMETHOD.                    "get_data_list
      METHOD get_data_list_suisse.
        WRITE 'Suisse'.
      ENDMETHOD.                    "get_data_list_suisse
    ENDCLASS.                    "lcl_ee_data IMPLEMENTATION
    DEFINE MACRO
    DEFINE launch.
      data: l_method type string.
      l_method  = 'get_data_list'.
      concatenate l_method &2 into l_method separated by '_'.
      write l_method.
      call method &1->&2.
    END-OF-DEFINITION.
    START-OF-SELECTION.
      DATA : l_ee TYPE REF TO lcl_ee_data.
      CREATE OBJECT l_ee.
      launch l_ee 'suisse'.

    Hi,
    partly...
    From the ABAP documentation:
    +Using the standard ABAP parenthesis semantics you can call methods dynamically.
    ·     Calling an instance method meth:
    CALL METHOD ref->(f)
    ·        Calling a static method meth:
    CALL METHOD class=>(f)
    CALL METHOD (c)=>meth
    CALL METHOD (c)=>(f)
    ·        Calling a user-defined method meth:
    CALL METHOD (f)
    CALL METHOD ME->(f)
    +
    Regards,
    Gianpietro

  • Implementing object type methods

    I am having some problems with the object type method implementation.
    I have poured over the docs and so far they have lead me to a dead end each time.
    I am trying to implement a pl/sql object with methods that map to methods in a corresponding java class. The code is as follows:
    the java class:
    package possystems.poseqdb;
    public class ObjTypeCallSpecTest {
         private String teststring;
         public void mutateString() {
              this.testString = "the second value";
    the oracle object type:
    create type objecttesttype as Object (
    teststring varchar2(255),
    member procedure objtest as language java
         name 'possystems.poseqdb.ObjTypeCallSpecTest.mutateString()'
    the anonymous pl/sql block calling the method:
    declare
    auth1 objecttesttype;
    begin
    auth1:=objecttesttype('the first string');
    dbms_output.put_line('1 '||auth1.teststring||' 1');
    auth1.objtest();
    dbms_output.put_line('2 '||auth1.teststring||' 2');
    end;
    There is nothing fancy going on here. The problem I have is the auth1.objtest() call allways returns the following error:
    1 the first string 1
    declare
    ERROR at line 1:
    ORA-00932: inconsistent datatypes
    ORA-06512: at "ANDRE.OBJECTTESTTYPE", line 0
    ORA-06512: at line 6
    Note the first line of output is the first dbms_output message indicating the object was properly instantiated.
    Could someone please let me know what stupid little thing I have overlooked or have misunderstood from the oracle docs.
    Andre

    >
    Use object types as data structures to be manipulated using packages, and ignore the type body possibility.
    >
    Well that would be throwing away a powerful part of the TYPE functionality.
    The methods in the type body can be, and often are, used to provide multi-column validation to prevent the creation of invalid instances. A simple example is an ADDRESS_TYPE (e.g. ADDRESS1, ADDRESS2, CITY, STATE, ZIP) where a valid instance must have a value for each attribute except ADDRESS2 which might be optional.
    The constructor and the methods in the body can perform validation to ensure that the components meet certain minimum requirements: not null, length (a 1 byte address wouldn't make much sense), character or numeric content, etc. A SET_ADDRESS1 method can also perform those validations.
    That allows instances of those types to be used by PL/SQL code without repeated validation of the attributes. I use such basic TYPEs extensively in ETL and reporting processes. Even something as simple as a TYPE that has FROM_DATE and TO_DATE benefits by having constructor and body methods that prevent the attributes from being NULL and ensure that any TO_DATE is later than the FROM_DATE.

Maybe you are looking for

  • How do I move my Itunes library to a new hard drive????

    Hi! I recently installed a new and bigger hard drive and wanted to move my itune library to it. Someone here said that if I do that, I will have to manually reintall each song into Itunes. Is this true? is there a way that i would move it and cause m

  • 39L22U as PC Monitor: Resolution Problem

    I recently purchased the 39L22U model. I was using HDMI from my laptop and getting full 1920x1080 resolution. I added another HDMI device to my system and moved my laptop to the VGA(PC) port, but now the max resolution I can set is oddly 1360x768. Ei

  • Validation on commit

    Guys, I have a af:table. User create rows, input values etc.. but the validation should be fired only on 'commit'. also invalid rows should be marked by some means. how this can be acheived? Thanks in advance.

  • Sap xi SCENARIO source directory working ,but not working target directory

    sap xi SCENARIO source directory working ,but not working target directory.. plz help me

  • Cannot use DSUB function in Business Logic Callable Object

    Hi sdners! I am trying to create a Business Logic Callable Object, that compares a date and actual date. I used DSUB like this: DSUB(DVAL(DSTR(NOW(),'DATE')),DVAL(DSTR(@beginning_date,'DATE')),'D') @beginning_date is of type Date. DSUB should return