Hascode without instance variable: Urgent

Hi All
I have to write hashCode() method correspond to the equals() method in the same class.
But I dont have any class level variable in this class, I am not able to generate the hashCode() method automatically from Eclise.
My equals method looks like this -
public abstract class Value implements iValue
public boolean equals(Object object) {
return (compareTo(object) == CMP_EQUAL);
CMP_EQUAL value is a instance variable of iValue interface.
Can anyone suggest me how to write hashcode for this class?
Thanks.

malcolmmc wrote:
If the class has no state associated with it then there's no reason to write either hashCode or equals methods for it, since there's no basis for such comparison except instance identity (which is the default).
In fact instances of a stateless class are interchangeable.If they really were completely interchangeable, then you would want an equals which returns true and hash code which returns a constant value.

Similar Messages

  • Binding: Instance variable loses value.

    Hi all,
    Just making my first steps into Objective-C, I've done a lot of C, C++ and C# on win & linux. Anyhow, I've been hacking away happily and discovered a peculiar behaviour, and I'm not sure if it's my code or some obscure bug in Xcode.
    1. I have a Check Box(NSButton) directly bound to a BOOL instance variable called "checkValue" using KVC. The containing class is a custom NSView subclass.
    2. I manually implemented the setter according to KVC naming rules "setCheckValue".
    3. When debugging the UI (check box) calls the setter perfectly with the correct value, which shows up in the NSLog output.
    4. I hooked up the action for the check box as well, and inside the action handler the instance variable reports the value correctly. Everything looks fine.
    5. Now here's the rub. I put a mousedown event handler into the class as well, and it is called flawlessly when I click on the custom view. However, "checkValue" does not report the correctly set value.
    So, how can a class instance variable, which is set and reports correctly elsewhere in the same scope, all of the sudden take on a nonsense value in a event handler? If a variable has a value set, it should be the same everywhere within the same scope!
    Below is simplified code extracted from the original project for clarity. It produces exactly the same behaviour as the more complex project without the distracting code.
    #import "CheckBoxHandler.h"
    @implementation CheckBoxHandler
    @synthesize checkValue;
    //Apparently this is required for binding in NSView based classes
    //The same behaviour occurs even if you remove this.
    +(void)initialize
    [self exposeBinding:@"checkValue"];
    -(id)initWithFrame:(NSRect)frameRect
    self = [super initWithFrame:frameRect];
    if(!self)
    return nil;
    [self setCheckValue:YES];
    return self;
    //manual impelementation of KVC setter
    -(void)setCheckValue:(BOOL)v
    checkValue = v;
    NSLog(@"Setter Called: checkValue is %d", checkValue);
    //The action works fine as evidenced by Log output
    //Check and uncheck the box a few times.
    -(IBAction)checkBoxAction:(id)sender
    NSLog(@"UI State:%d Ivar State: %d", [checkBox state], checkValue);
    //Mouse clicking on the view calls into this event.
    //The problem is the value reported by [self checkValue] OR checkValue directly
    //do not match the UI state. In fact it always reports some nonsense value.
    -(void)mouseDown:(NSEvent *)event
    NSLog(@"Inside Mousedown: checkValue is: %d", [self checkValue]);
    @end
    I have a workaround, but it really bends my head when something doesn't behave as expected!

    I have synthesized against "checkValue", although I manually implemented the setter so I could set a breakpoint and observe the value. I thought [self checkValue] and self.checkValue both simply call the same getter, just different syntax.
    The setting of the value using the UI checkbox happens outside of the event call chain. I can check and uncheck the checkbox and the value changes correctly. The checkbox is in a separate space on the window, so clicking it does not activate mousedown on the view, this is correct behaviour. Clicking on the view does activate the mousedown event, this is done after I've set the checkbox so the value has been set well before the mousedown event. Thus it should already have the correct value in the event.
    For completeness this is the interface file:
    #import <Cocoa/Cocoa.h>
    @interface CheckBoxHandler : NSView {
    IBOutlet NSButton *checkBox;
    BOOL checkValue;
    -(IBAction)checkBoxAction:(id)sender;
    @property (assign, readwrite) BOOL checkValue;
    @end
    I'll change everything to self.checkValue just for the excercise. Ok, done. checkValue still reports a value of 1 in the mousedown event regardless of the value set elsewhere.

  • Null Instance Variables on Screenflow

    Hi,
    I have some problems with instance variable of type BPM Objects in a Screenflow.
    I always create automatic processes without user interaction, and on server side I have seen that it's not necessary to instantiate an instance variable. Moreover if within a method I write (I use the Java style syntax):
    String a;
    a.toString(); // just to call a method on a not-instantiated variable
    everything works correctly, the "a" variable is automatically instantiated.
    But it seems that in an automatic activity of a Screenflow it's different, I need to do the new also for Instance Variables.
    Then, in the Screenflow I have an Instance Variable myObject of type MyObject that is a BPM Object. This object has an attribute myStrings that is an array of String.
    To instantiate the instance variable I can write:
    myObject = new MyObject();
    But then I get a java.lang.*NullPointerException* when I call the extend method of its attribute myStrings to add a string.
    Do you agree with me that on the Screenflow code it's necessary to instantiate the variables?
    How can I instantiate an Array of String?
    Thank you.

    Thanks Daniel, I'm using ALBPM 6.0,
    i know the line where I get the exception, I have a logMessage before and after each line of code, and then in the exception stack there is the PBL Method line indicated:
    Caused by: java.lang.NullPointerException
         at xobject.Fuego__AutoGen__Screenflows__.__ScreenflowConJsp.automatic1(__ScreenflowConJsp.xcdl:*19*)
    19 is the code line where I get the exception. In this line I have this:
    myObject.myStrings.extend(arg1 : a);
    but the null object is not the array, it's myObject that is an Instance Variable.
    In ALBPM60_Studio_ReferenceGuide at chapter Programming Styles paragraph Java Programming Style there is:
    This style emulates Java syntax and adds several features to match PBL expressions. These added features include:
    • Output arguments
    • Input and display statements
    • Variable auto-initialization
    In fact in my previuos BPM projects I have seen that is not necessary to istantiate the variables, both for Instance Variable and local variable declared within a method. In my previous post I did an example:
    String a;
    a.toString();
    Usually this causes an Exception, but not in ALBPM methods.
    My main question is: is it possible that this is true just for Server side methods and not for Screenflow methods? Because in my case I need to instantiate every Instance Variable of my Screenflow (for example the myObject instance variable) in an Automatic Activity I have put as first Activity of the flow.
    Thanks again for your help.

  • Using multiple instance variables or BPM objects in a single JSP

    In my screenflow, for an user activity, I've selected a BPM object variable for my JSP and using this BPM object variable within the JSP to display or accept values related to this BPM object.
    But in certain circumstances, I need access to some of the instance variables defined in my screenflow (which are not members of the BPM object), and to get these variable values displayed in my JSP. I don't want to overload my BPM object with all these instances as they do not logically fit as members in this BPM object.
    For example, if I need to capture and display the logged in user name across the JSPs in my web application, then how can I do that without specifying this user variable in all of my BPM objects.
    Is there any extensibility in using more than one BPM object variables in my JSPs? Why is it that a single BPM object variable is tied to a JSP? Or am I missing something else here?

    I'm with the same problem!

  • JDEVELOPER 10G, ADF BC: Passivate static instance variables in AM?

    I understand the need to passivate/activate instance variables but what about static instance variables within an application module?
    Thanks,
    Wes

    Static variables - being class variables and not instance variables - persist without a need for passivation. Is there a particular reason or scenario why to use static variables? You have to consider that since all AM instances will share it, changing it in one AM instance - i.e. one user session - will affect all other AM instances - i.e. all other user sessions! You also have to consider the implications of multithreading when attempting to modify the static variable.

  • Accesing Instance Variables

    Hi there!
    I have a process and I want to check certain restrictions once a day and if the result of this checks is positive I want to send a notification to other process to continue.
    I've tried to use a global automatic activity but it seems to me that it doesn't has access to the instance variables because I've set some Logs and they return always empty even if the variables of the object accessed are correctly fulfilled.
    The other solution is to use the project variables but this variables are less flexible to changes on the restrictions.
    My questions are:
    ¿Can I really correctly access to the instance variables from a global automatic activity? -> If this is true then. ¿What may I be doing wrong?
    ¿Is there any other way to do this?
    Thanks for reading and double thanks for reply.

    It's sounds at least too tricky because you will have to launch and interactive activity from code.
    Anyways an interactive activity requires user interaction and the point of the time-based activity is to execute code at night without the need of an user.
    The most frustrating thing is that when i'm coding the method of the global automatic activity and I write "this." the popup shows all the instance variables so I thought that I could access them.
    Then I write some logs to be sure but when the method was executed they return all empty.
    If I can't solve this I will have to use the project variables through the instant processor and all the variables for the restricctions have to be simple typed not objects with the lack of flexibility that it's implies.

  • Need a little help with instance variables

    I'm still pretty new to this, but what I have here is some instance
    variables that I need to constuct a record from. This keeps track of a
    sorting process. In the public Sortable getRecord() method is where
    I need to construct that record, which is where I'm lost.
    I look at the tutorials on this site but still can't seem to find what I'm looking for.
    What's giving me so much trouble is that I have variables of different types
    and I can't out how to group them togther without getting some wierd error.
    public class SortableSpy implements Sortable {
        public Sortable a; // Sortable is an interface that this class inplements
        public int swaps;
        public int compares;
        public SortEvent events [];
        public int nevents;
        public SortableSpy(Sortable arr) {
                a = arr;              // These are
                swaps = 0;
                compares = 0;  // the variables I need
                nevents = 0;
                events = new SortEvent[1000];  // to use
        public Sortable getRecord() {
             // and this is where I need the record to be constructed
           // then another class will call this record which will keep track
          // of compares and swaps
              return ;
         Thanks for any help anybody can give me

    Why do you have a field that's the same type
    (implements the same interface) as the class itself?
    This is possible, of course, but what are you hoping
    to achieve by doing so?The interface was pre set-up by my professer. Here is the interface
    public interface Sortable  extends Stringable {
        public int size(); // Number of objects to sort
        public boolean inOrder(int i, int j); // are objs i and j in order?
        public void swap(int i, int j); // Swap objects at i and j
        public Stringable getS(int i);  // For debugging - make an
                                      // object being sorted stringable
    }>
    Your code would be easier to read, both for the
    person grading your homework and for anyone who wants
    to help you here, if you chose variable names that
    have meaning. "a" doesn't qualify.What "a" is suppose to be is an object that is sortable. So when I use a sorting
    algorithim it will sort "a". This part was also setup by my proffeser.
    >
    Where do you expect to get all the data that will go
    into those fields?I should've put the entire class here before, instead of just the constuctor
    here it is:
    public class SortableSpy implements Sortable {
        public int t;
        public Sortable a;
        public int swaps;
        public int compares;
        public SortEvent events [];
        public int nevents;
        public SortableSpy(Sortable arr) {
                a = arr;
                swaps = 0;
                compares = 0;
                nevents = 0;
                events = new SortEvent[1000];
        public Sortable getRecord() {
              return a;
         // ** construct a SortRecord from the instance variables
        public String brief() { // or here
                return "Number Of Events" + this.hashCode() + " (" + nevents + ")";
        public String verbose( ) {
              return "Number Of Compares" + this.hashCode() + " (" + compares + ")" +
              "Number Of swaps" + " (" + swaps + ")";
        public boolean inOrder(int i, int j) {
            compares++;
            SortEvent ev = new SortEvent();
            ev.i = i;
            ev.j = j;
            ev.e = EventType.Compare;
            events[nevents] = ev;
            nevents++;
         return a.inOrder(i,j);
        public void swap(int i, int j) {
                int temp = i;
                i = j;
                j = temp;
        public int size() { return nevents;};
        public enum EventType {compare, swap;
         public static Event Compare;}
        private class si implements Stringable {
                private int i;
                public si (int j) { i = j; };
                public String brief() { return " " + i;}
                public String verbose() { return this.brief();}
        public Stringable getS(int i) {
                return  a;
    }>
    getRecord may be better named "createRecord", if I
    understand what you're trying to do (I may not). But
    it sounds like this name may have been specified by
    your professor.
    Yeah get record is supose to return the number of times an
    algorithm swaps and compares objects during the sorting process
    sort of like spying in, as he described
    I get the impression that you've misunderstood a
    homework assignment.Unfortunaty I'm starting to think so myself, but thanks to both of you guys
    for the help you've giving me so far.

  • Inheritance & instance variables

    Okay, this just went against everything I thought I knew about inheritance and Java...
    So I wrote something like the code below, and when I declared
    ClassB cb = new ClassB();
    cb.variable2 was set to "". I traced it line-by-line in JBuilder's debugger, and I watched it set it to "bar" with my very own eyes, and then the tracer went to the "String variable2 = "";" line AFTER it ran the constructor. Is that supposed to happen?
    class ClassA{
         String variable1 = "";
         ClassA()
             parse();
         protected void parse()
              variable1 = "foo";
    class ClassB extends ClassA
        String variable2 = "";
        ClassB()
            super();
        protected void parse()
            super.parse();
            variable2 = "bar";

    And also: for those of you who said "never use an
    overridable method in the constructor," does this mean
    that every time you create a subclass, you must write
    a constructor that initializes all of the instance
    variables? Not exactly sure what you mean by "initializes all of the instance variables." You certainly don't need to explicitly initialize each of your object's fields in the constructor; in some cases, you won't know their values at that time.
    Doesn't this cause you to have to change all the subclasses
    individual subclasses if you ever needed to remove or change
    a superclass' instance variable (for example)?No, and this comes back to my point that a class is only responsible for the fields that it declares. If you don't try to change your superclass' fields directly, then you're not dependent on how it's implemented. Instead, you should call the appropriate superclass constructor. For example:
    public class XXX
        protected Map     _data;
        public XXX()
            _data = new HashMap();
        public XXX( Map data )
            _data = data;
    }Let's say that you now want to create class YYY, which extends XXX but uses a TreeMap instead of a HashMap. You could simply access "_data" directly; after all, it's "protected" and not "private". However, this introduces a dependency: class XXX now cannot change field "_data" without breaking class YYY. Instead, you should call the second constructor, which initializes the field from passed data:
        public YYY()
            super(new TreeMap());
        //...There are still ways that this example could break ... for example, the implementor of XXX could decide that the second constructor should copy the passed Map. There are ways to avoid this, but we won't go into those here :-)

  • Global instance variables

    is it possible to have instance variables, in this particular case a vector, that is globally accessible by all classes in the program? am i being totally blind or am i barking up the wrong tree?

    is it possible to have instance variables, in this
    particular case a vector, that is globally accessible
    by all classes in the program? am i being totally
    blind or am i barking up the wrong tree?As previously stated you can always have a class that has a public static Vector (it should probably also be final.) If you need a Vector that is shared or any other object for that matter, it is usually better to make the static member provate so that you can limit access to the instance. Your class would then contain the methods that are needed to udpate ad retrieve from the Vector without exposing it to every class.
    Also if you do this, you can use ArrayList instead. Vector is synchronized whether you need it or not. This can be slow so you can use ArrayList which does the same thing and synchronize only the methods in your class that need to have synchronization. If you are using mutliple threads (if you use Swing or AWT you do) you need synchronization.

  • Convertion of class variable (static) into instance variable(non-static)!

    Dear all,
    got a slight different question.
    Is that possible to convert class variable (static) into instance variable(non-static)?
    If so, how to make the conversion?
    Appreciating your replies :)
    Take care all,
    Leslie V
    http://www.googlestepper.blogspot.com
    http://www.scrollnroll.blogspot.com

    JavaDriver wrote:
    Anything TBD w.r.to pass by value/reference (without removing 'static' keyword)?Besides the use of acronyms in ways that don't make much sense there are two other large problems with this "sentence".
    1) Java NEVER passes by reference. ALWAYS pass by value.
    2) How parameters are passed has exactly zero to do with static.
    Which all means you have a fundamentally broken understanding of how Java works at all.
    Am I asking something apart from this?
    Thanks for your reply!
    Leslie VWhat you're asking is where to find the tutorials because you're lost. Okay. Here you go [http://java.sun.com/docs/books/tutorial/java/index.html]
    And also for the love of god read this [http://www.javaranch.com/campfire/StoryPassBy.jsp] There is NO excuse for not knowing pass-by in Java in this day and age other than sheer laziness.

  • When can I make instance variables public?

    I noticed that some of the in-built Java classes have public instance variables, for example in Rectangle the variables x, y, width and height are all directly accessible from outside. When is it okay to make public instance variables? Is it when they are primitive types? I thought maybe it is when they are final variables - but that can't be the case because you can directly modify the Rectangle's public instance variables.
    I've always used getter and setter methods in my objects because I was told "making instance variables public is bad". But obviously this isn't necessarily the case (unless the guys at Java are bad programmers). I think directly accessing the instance variables makes for much neater and more readable code. Is there any convention or best-practise guidelines on when I can or can not make them public?
    P.S. I also just "don't get" why you can't make them public if you're just going to provide a getter and setter method anyway... what's the difference? I suppose the theory is that the setter method should do some checking to make sure the input is valid. But what if the setter method just accepts -anything- of the appropriate type (accepts any Rectangle, for example)? What's the use of hiding the instance variables?
    teach me.
    Thanks. ;-)

    For the most part, it is true that making instance member variables other than private is not a good idea. This concept, known in OO circles as "information hiding", typically allows the greatest flexibility in internal implementation of a class, since you can change the internal structure of the class without affecting the clients that use the class.
    Let me add that Sun's programmers are a team, and teams have members of differing capabilities.
    It is also true that there may be cases where exposing instance variables is unlikely to cause problems. Simple classes, or very stable classes that will not change are some examples, but not all.
    Following a guideline blindly is not a good idea either. You need to evaluate each instance in which you decide you might want to deviate from "good programming practices". Still, best practices are best practices for a reason. It is best to understand them, and then decide if you can violate them.
    For my own part, I don't think it is "neater" to expose such variables, and I have personally had to deal with situations where a change in a class's internal structure was extremely painful because the original developer chose to make all his instance variables public.
    {?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Hit testing without instance names

    I know its possible to hit test From something without an instance name if you have it in a seperate .as file. All you have to do is type in this.hitTest(InstanceName);
    But, Is it possible to do a hit test from something without an instance name against something else that dosent have an instance name?
    this.hitTest(Other);
    And if so is it possible to assign the other object to a variable?
    var Target:Obj;
    Target = this.hitTest(Other);
    these are just my theories as to what the code should look like, Can anyone confirm that its correct, deny that its possible, or show me how it should look? Thanks in advance.

    well, in the beggining of the program there wont even be any hit tests to do. but as the program goes on, later to have to do around 9-10 hit tests per second. as i know that its not what you do, but how many times you do it that slows up a computer, would this effect the programs performance at that rate?
    Date: Fri, 18 Jun 2010 15:27:06 -0600
    From: [email protected]
    To: [email protected]
    Subject: Hit testing without instance names
    if you spawn n objects, you have n*(n-1)/2 hittests to check.  that's the way it is unless you use a technique to decrease that work-load.  and techniques to do just that do exist.
    but in your situation it sounds like you have have 2 or 3 objects to check for hittests which means you only have 1 or 3 hittests to check.
    >

  • Parsing XML and Storing values in instance variable

    hi,
    i'm new to XML.
    here i'm trying to parse an XML and store their element data to the instance variable.
    in my main method i'm tried to print the instance variable. but it shows "" (ie it print nothing ).
    i know the reason, its becas of the the endElement() event generated and it invokes the characters() and assigns "" to the instance variable.
    my main perspective is to store the element data in instance variable.
    thanks in advance.
    praks
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class mysax extends DefaultHandler
         String ctelement;
         CharArrayWriter contents;
         String vname1,vrcbreg1,vaddress1,vcountry1,vtelephone1,vfax1;
         String vname,vrcbreg,vaddress,vcountry,vtelephone,vfax;
         public mysax()
              vname1 = null;
              vrcbreg1 = null;
              vaddress1 = null;
              vcountry1 = null;
              vtelephone1 = null;
              vfax1 = null;
              contents= new CharArrayWriter();
         public void doparse(String url) throws Exception
              SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    ParserAdapter pa = new ParserAdapter(sp.getParser());
    pa.setContentHandler(this);
    pa.parse(url);          
         public void startElement(String namespace,String localName,String qName,Attributes atts)
              ctelement = localName;     
         public void endElement(String uri,String localName,String qName) throws SAXException
         public void characters(char[] ch,int start, int length) throws SAXException
              try
                   if(ctelement.equals("name"))
                        vname = new String (ch,start,length);
                        System.out.println("The method "+vname1);
              }catch (Exception e)
                   System.out.println("The exception "+e);
         public static void main(String args[])
              try
              mysax ms = new mysax();
              ms.doparse(args[0]);
              System.out.println("the contents name "+ms.vname1);
              catch(Exception e)
                   System.out.println("this is exception at main" +e);
    my XML looks like
    <coyprofile_result>
    <company>     
    <name>abcTech</name>
    <rcbreg>123456789</rcbreg>
    <address>Singapore</address>
    <country>sg</country>
    <telephone>123456</telephone>
    <fax>123155</fax>
    </company>
    </coyprofile_result>

    I believe that the problem has to do with the value you assign to ctelement. You are assigning the value of localName to ctElement, however for the element: <name>...</name> the localname is empty string i.e. "", but qName equals "name". Because you are assigning empty string to ctElement, when you do the comparison in characters of ctElement to "name" it will always be false. So in startElement change it to ctElement = qName; Try it and see if it works. I have produced similar programs and it works for me.
    Hope this helps.

  • How to use an BPM Instance Variable in JSP page

    Hi All,
    I am using the JSP Presentation, but i don't know how to use an Instance variable in JSP page, that instance already declared in the process. And Can u explain the syntax that to include the JS file into jsp page
    Regards
    Vasu.
    Edited by bpmvasu at 04/03/2007 10:43 PM

    Hi Mariano,
    I'm using JSP presentation too. In "Interactive Component Call" active i'm using "Use JSP presentation", but i only can define one instance variable, i need to add more instance variables. In "Advanced" option of this task, i have the argument mapping .. but i don't understand how to use it.
    I have a instance variable called "genders" of the type String[Int] (Associative Array) and i'm mapping this instance variable in "Arguments Show In" option of the advanced option of JSP presentation. In JSP presentation i have the code:
    <select <f:fieldName att="person.gender"/>>
                   <c:forEach var="gender" begin="0" items="${genders}" varStatus="status">
                        <c:choose>
                             <c:when test="${person.gender == gender}">
                                  <option value="<c:out value="${gender}"/>" selected="true"><c:out value="${gender}"/></option>
                             </c:when>
                             <c:otherwise>
                                  <option value="<c:out value="${gender}"/>"><c:out value="${gender}"/></option>
                             </c:otherwise>
                        </c:choose>
                   </c:forEach>
              </select>And in my screenflow i have the code:
    genders[0] = "Male"
    genders[1] = "Female"But when i run my application, i have the error: "The task could not be successfully executed. Reason: 'java.lang.ClassCastException: java.lang.Integer'."
    What's the problem?

  • How to change value of instance variable and local variable at run time?

    As we can change value at run time using debug mode of Eclipse. I want to do this by using a standalone prgram from where I can change the value of a variable at runtime.
    Suppose I have a class, say employee like -
    class employee {
    public String name;
    employee(String name){
    this.name = name;
    public int showSalary(){
    int salary = 10000;
    return salary;
    public String showName()
    return name;
    i want to change the value of instance variable "name" and local variable "salary" from a stand alone program?
    My standalone program will not use employee class; i mean not creating any instance or extending it. This is being used by any other calss in project.
    Can someone tell me how to change these value?
    Please help
    Regards,
    Sujeet Sharma

    This is the tutorial You should interest in. According to 'name' field of the class, it's value can be change with reflection. I'm not sure if local variable ('salary') can be changed - rather not.

Maybe you are looking for