Unable to pass enum to a method

I am trying to use a enumation to list all the graphics drivers available and when I pass it from my main class to a another objects setGraphicsDriver method (with corresponding argument) I get the error:
init:
deps-jar:
Compiling 2 source files to C:\Documents and Settings\Sean\Desktop\Java Projects\EngineFramework\build\classes
C:\Documents and Settings\Sean\Desktop\Java Projects\EngineFramework\src\engineframework\Main.java:29: setGraphicsDriver(engineframework.IrrlichtEngine.GRAPHICS_MODE) in engineframework.IrrlichtEngine cannot be applied to (engineframework.Main.GRAPHICS_MODE)
ie.setGraphicsDriver(myobj);
1 error
BUILD FAILED (total time: 0 seconds)
Here is my main class:
package engineframework;
public class Main {
static enum GRAPHICS_MODE { NULL, SOFTWARE, OPENGL, DX8, DX9 }
public static void main(String[] args) {
IrrlichtEngine ie = new IrrlichtEngine();
GRAPHICS_MODE myobj = GRAPHICS_MODE.OPENGL;
ie.setGraphicsDriver(myobj);
ie.initialiseDevice();
The setGraphicsDriver method that fails:
public void setGraphicsDriver(GRAPHICS_MODE gm) {
System.out.println(gm); // debugging info
// Ensure that the gm GRAPHICS_MODE is actually initialised, if not set it to OPENGL
if(gm == null) {
gm = GRAPHICS_MODE.OPENGL;
switch(gm) {
case NULL:
graphicsDriver = E_DRIVER_TYPE.EDT_NULL;
break;
case SOFTWARE:
graphicsDriver = E_DRIVER_TYPE.EDT_SOFTWARE;
break;
case OPENGL:
graphicsDriver = E_DRIVER_TYPE.EDT_OPENGL;
break;
case DX8:
graphicsDriver = E_DRIVER_TYPE.EDT_DIRECT3D8;
break;
case DX9:
graphicsDriver = E_DRIVER_TYPE.EDT_DIRECT3D9;
break;
default:
graphicsDriver = E_DRIVER_TYPE.EDT_SOFTWARE;
break;
I am sure its something really silly but its driving me nuts :)

I think I am close, this is what I now have:
private static E_DRIVER_TYPE graphicsDriver = null;
/// GRAPHICS_MODE - List of all available graphics modes
private static enum GRAPHICS_MODE {
NULL (E_DRIVER_TYPE.EDT_NULL),
SOFTWARE (E_DRIVER_TYPE.EDT_SOFTWARE),
SOFTWARE2 (E_DRIVER_TYPE.EDT_SOFTWARE2),
OPENGL (E_DRIVER_TYPE.EDT_OPENGL),
DX8 (E_DRIVER_TYPE.EDT_DIRECTX8),
DX9 (E_DRIVER_TYPE.EDT_DIRECTX9);
// Has to return a value...?
private GRAPHICS_MODE(E_DRIVER_TYPE edt) {
this.graphicsDriver = edt;
public E_DRIVER_TYPE getGraphicsDriver() {
return graphicsDriver();
Now the code return an error that I need to provide a return value (see program comment). I am not sure why I would need to do that since I looked up some more advaned enum examples and I see it being done the way that you informed me of.
Also thanks for the assistance, too bad they don't include this tips in books :)

Similar Messages

  • Passing Enum Values to a common method.Please see

    How do I pass the value of an Enum to a method?
    I have an Enum called myEnums with several values to a common method
    public enum MYEnums {
            FULL,
            EMPTY,
            PARTIAL
            CPTY_CODE;
    //Invoke
    isEmpty(myEnums.FULL)
    isEmpty(myEnums.EMPTY)
    // common method
    isEmpty(String enumValue){
    myEnum.enumValue
    ERROR: enumValue cannot be resolved

    You could also write this:
    public enum FillLevel
        FULL,
        EMPTY,
        PARTIAL;
        public boolean isEmpty() {
          return this == EMPTY;
        public boolean isFull() {
          return this == FULL;
    }By the way. What does CPTY_CODE mean? It doesn't seem as if it belongs into the enum. Also, why doesn't the enum have a name that tells us what it's all about?

  • Enums with common method implementation.

    Working with JDK 1.4 , i had some typesafe enums with common methods in an abstract class. Because of some issues, i want to migrate them to 'enums' provided in JDK 5.
    As enum provided in JDK 5 can neither be extended or derived from any other class, i am unable to achieve my objective.
    Is there any way out, or should i continue to live with my old code?
    Thanks,
    Prabhaker

    Well, there's always this ugly pretend-you-have-multiple-inheritance sort of construct:
    public class CommonEnumUtilities
        // the following method is the actual implementation of method foo
        public static void foo(Enum e, Object... otherParams)
    public interface CommonEnumInterface
        // the following ensures that you have the method foo
        public void foo(Object... otherParams);
    public enum SomeEnum implements CommonEnumInterface
        public void foo(Object... otherParams)
            CommonEnumUtilities.foo(this, otherParams);
    }I personally find this approach revolting, but I guess it's better than nothing.

  • Passing enums as arguments within a jni function

    I am trying to pass enum arguments from a Java/JNI function to a C function. For example,
    public native void java_func(enum pname);
    java_jni_func(JNIEnv * env, jobject panel, enum pname)
    c_func(pname);
    where
    c_func(enum pname);
    But I get the error message "illegal use of this type as an expression"
    Any ideas on how I go about solving my problem.

    Hi DavidBray,
    Your task is very simple, you can pass enum value as argument ( do not pay attention to the message above ). You need only to get the name of an enum value in native method. I wrote you a simple example in MS Windows.
    Here is the code in Java:
    package test;
    public class JEnumToJNI {
         static {
              System.loadLibrary("JNIJEnumToJNI");
         public enum JEnum {
             Ok,
             Cancel
         public static void main(String[] args) {
              PrintEnumValue(JEnum.Ok);
              PrintEnumValue(JEnum.Cancel);
         static native void PrintEnumValue(JEnum val);
    }The native method extracts the name of enum value and prints it. This is code of JNI module:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <stdio.h>
    #include <string>
    #include "test_JEnumToJNI.h"
    using namespace std;
    // Converts jstring to string object
    string jstring2string(JNIEnv *env, jstring js)
        string result;
        long len = env->GetStringUTFLength(js);
        char* p = (char*)malloc(len + 1);
        memset(p, 0, len + 1);
        if(len > 0)
            env->GetStringUTFRegion(js, 0, len, p);
        result = p;
        free(p);
        return result;
    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
        return TRUE;
    JNIEXPORT void JNICALL Java_test_JEnumToJNI_PrintEnumValue(JNIEnv* env, jclass, jobject enumVal)
        // Get enum class
        jclass jclassEnum = env->GetObjectClass(enumVal);
        if(jclassEnum != 0)
             //Get toString() method
            jmethodID toString_ID = env->GetMethodID(jclassEnum, "toString", "()Ljava/lang/String;");
            //Get enumVal name
            jstring jstrEnum = (jstring)env->CallObjectMethod(enumVal, toString_ID);
            fprintf(stdout, "enum value: %s\n", jstring2string(env, jstrEnum).c_str());
            // Delete local references created
            env->DeleteLocalRef(jstrEnum);
            env->DeleteLocalRef(jclassEnum);
        else
            // If jclassEnum == 0 clear Java Exception
            env->ExceptionClear();
    }The header generated with javah.exe
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class test_JEnumToJNI */
    #ifndef _Included_test_JEnumToJNI
    #define _Included_test_JEnumToJNI
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     test_JEnumToJNI
    * Method:    PrintEnumValue
    * Signature: (Ltest/JEnumToJNI/JEnum;)V
    JNIEXPORT void JNICALL Java_test_JEnumToJNI_PrintEnumValue
      (JNIEnv *, jclass, jobject);
    #ifdef __cplusplus
    #endif
    #endifYour task is very simple and you need not to substitute enum values with numbers.

  • Unable To Pass Input Page Parameter Using PageDef File.

    Dear All,
    I am currently exploring task flows as I dont have that much knowledge in it.
    Here's my use case
    1. I setup a taskflow which has a Method Call and a View Activity in it.
    2. The method call is a default activity which just calls a web service.
    3. After execution, I just wanted to display the result of the method.
    I used input page parameters to pass data between the method call and the view activity.
         (I passed the data by accessing the pagedef file directly. I know I can do it using pageflowscope..but this is
         my self exercise so that I could understand ADF fully );)
    <?xml version="1.0" encoding="windows-1252" ?>
    <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
      <task-flow-definition id="ManageEmployeeTaskflow">
        <view id="viewEmployee">
          <page>/viewEmployee.jsff</page>
          <input-page-parameter>
            <from-value>#{data.com_test_ManageEmpFlow_methodPageDef.empInfoIterator.currentRow.dataProvider.name}</from-value>
            <to-value>#{data.com_test_viewEmployeePageDef.name.inputValue}</to-value>
          </input-page-parameter>
        </view>
        <method-call id="EmployeeSetup">
          <method>#{bindings.EmployeeSetup.execute}</method>
          <outcome id="__12">
            <fixed-outcome>viewEmployee</fixed-outcome>
          </outcome>
        </method-call>
        <use-page-fragments/>
      </task-flow-definition>
    </adfc-config>Problem is, when I display the data. Nothing is being displayed.
    <af:inputText value="#{bindings.name.inputValue}"
                      label="#{'Name'}"/>          I debug the taskflow and the <from-value> really has a value, but I am not sure why it cant be passed to next pagedef.
    Any idea please?
    Edited by: Marky on May 15, 2011 11:25 PM

    Hi,
    I've been thinking... Is this way of passing parameters not possible?
          <input-page-parameter>
            <from-value>#{data.com_test_ManageEmpFlow_methodPageDef.empInfoIterator.currentRow.dataProvider.name}</from-value>
            <to-value>#{data.com_test_viewEmployeePageDef.name.inputValue}</to-value>
          </input-page-parameter>Thanks.

  • Passing Parameters via Post Method from Webdynpro Java to a web application

    Hello Experts,
    I want to pass few parameters from a web dynpro application to an external web application.
    In order to achieve this, I am referring to the below thread:
    HTTP Post
    As mentioned in the thread, I am trying to create an additional Suspend Plug parameter (besides 'Url' of type String) with name 'postParams' and of type Map.
    But when I build my DC, I am getting the same error which most of the people in the thread have mentioned:
    Controller XXXCompInterfaceView [Suspend]: Outbound plug (of type 'Suspend') 'Suspend' may have at most two parameters: 'Url' of type 'string' and 'postParams' of type 'Map'.
    I am using SAP NetWeaver Developer Studio Version: 7.01.00
    Kindly suggest if this is the NWDS version issue or is it something else that I am missing out.
    Also, if it is the NWDS version issue please let me know the NWDS version that I can use to avoid this error.
    Any other suggestion/alternative approach to pass the parameters via POST method from webdynpro java to an external web application apart from the one which is mentioned in the above thread is most welcome.
    Thanks & Regards,
    Anurag

    Hi,
    This is purely a java approach, even you can try this for your requirement.
    There are two types of http calls synchronous call or Asynchronous call. So you have to choose the way to pass parameters in post method based on the http call.
    if it is synchronous means, collect all the values from users/parameters using UI element eg: form and pass all the values via form to the next page is nothing but your web application url.
    If it is Asynchronous  means, write a http client in java and integrate the same with your custom code and you can find an option for sending parameters in post method.
    here you go and find the way to implement Asynchronous  scenario,
    http://www.theserverside.com/news/1365153/HttpClient-and-FileUpload
    http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html
    http://digiassn.blogspot.com/2008/10/java-simple-httpurlconnection-example.html
    Thanks & Regards
    Rajesh A

  • Unable to Pass Parameters to I5Grid in SAP MII 14.0 SP05

    Hi Experts,
    There was a bug in SAP MII 14.0 SP04  where we were unable to pass parameters to I5Grid dynamically. I understand that this bug has been fixed in SP05 , so we applied following patches:
    Patches installed :
    a)      XMII05P_4-10008694.SCA
    b)      XMII05_0-10008694.SCA
    Note details mentioning this issue :
    2016927 - I5Grid does not take into account overridden parameters when updateGrid(true) is called
    But even after applying these patches, I am still not able to pass parameters to I5Grid dynamically from irpt page.  Does anyone have any insight to it? Is it working for any one of you?
    Regards,
    Kirti

    Hi Chirstian,
    I see this change working. I was doing a mistake while passing parameter to I5grid.
    What I was doing-
    Grid.getQueryObject().setParameter(1, linename);
    Correct Way:
    Grid.getQueryObject().setParameter("Param.1", linename);
    Thanks & Regards,
    Kirti

  • Unable to pass microphone audio to speakers

    I've been googling for an hour or so now but I'm unable to pass audio going into the mic to the speakers, I've my amp with a guitar hooked up and want to be able to hear what I'm playing through my speakers.
    I've checked in the systems preferences where the input is boosted up, and also in Audo MIDI Setup where I'm unable to check the box for "thru"
    If I've to use garageband for this it's fine. Please notice that recording works perfectly fine.

    Usually your sound input isn't redirected to your output, because for most users they are using a mic and this could create feedback. Since you are using your guitar amp to feed the audio to the input this of course won't happen to you - but there's no normal way to redirect your audio input to your audio output. There is a solution though.
    The app Soundflower allows you to redirect your input and output to different devices, including pointing either at the other. It's free, and you can download it here:
    http://www.cycling74.com/products/soundflower
    I used this on my first generation Mac mini (with no regular audio input jack) to record sounds playing on my system. Works absolutely great.

  • Passing parameter in a method

    hi i have a situation where i have to pass parameter to my method i don't what to pass the parameter define from the viewO because am not using parameter to query from the view,i just what to pass it to my procedure,my method is
                    public void submit_agr(String par_id,String dref_id,String tas_id,String agr_id){
                        ViewObject sub = this.findViewObject("AGR1");
                      i don't what to use this-> sub.setNamedWhereClauseParam("tas_id", tas_id); the tas_id is not in AGR1 VIEWO
                      // sub.
                        sub.executeQuery();
                        Row row = sub.first();
                        par_id = (String)row.getAttribute("par_id");
                        agr_id = (String)row.getAttribute("id");
                        callPerformSdmsLogon("SMS_FORM_TO_ADf.delete_agr(?)", new  Object[] {par_id,dref_id,tas_id,agr_id});
                    }

    i try this AM IN jDEVELOPER 11.1.2.1.0
                    public void submit_agr(String par_id,String dref_id,String tas_id,String agr_id){
                        ViewObject sub = this.findViewObject("AGR1");                 
                        Row row = sub.first();
                        sub.setNamedWhereClauseParam("tas_id", new Number(10));-how will i pass this to my procedure
                        sub.setNamedWhereClauseParam("dref_id", new Number(10));-how will i pass this to my procedure
                        par_id = (String)row.getAttribute("par_id");
                        agr_id = (String)row.getAttribute("id");
                        sub.executeQuery();
                        callPerformSdmsLogon("SMS_FORM_TO_ADf.delete_agr(?)", new  Object[] {par_id,dref_id,tas_id,agr_id});
                    }how will i pass the two prameter to my procedure
    Edited by: Tshifhiwa on 2012/07/01 3:14 PM

  • Unable to pass parameter in oracle procedure through unix shell script

    Hi Experts,
    I have oracle procedure where in I have to pass the value of procedure parameter through unix script.
    Follwoing is the sample procedure which i tried to exceute from the unix.
    Procedure:
    create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) AS
    sql_stmt varchar2(1000) := NULL;
    v_count number := 0;
    v_owner varchar2(100) := owner;
    begin
    sql_stmt:='select count(1) from '||v_owner||'.EMP@infodb where rownum<=10';
    execute immediate sql_stmt into v_count;
    DBMS_OUTPUT.PUT_LINE(sql_stmt);
    DBMS_OUTPUT.PUT_LINE(v_count);
    END;The script which I used is:
    Unix
    #!/bin/ksh
    parm=$1
    echo start
    sqlplus -s scott@DEV/tiger <<EOF >>result_1.txt
    set serveroutput on;
    select '$parm' from dual;
    exec owner.PRC_TESTING_OWNER('$parm');
    EOFThe script is working fine that is i am able to pass to parameter value through unix shell script. :)
    But if I want to pass the value of the owner in cursor , I am unable to pass this value through unix.
    Following the procedure which i am trying to implement.
    create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) IS
    v_owner varchar2(100) := owner;
    CURSOR main_cur IS 
      select
      i.ROWID  rid ,
      emp_name,
      deptid
      from v_owner.employee;
    CURSOR subset_cur(c_deptid NUMBER ) IS
        SELECT *
          FROM v_owner.DEPT d
          where  d.dept_id=c_deptid;
    --##main loop     
    FOR i IN main_cur LOOP
          FOR j IN subset_cur(i.deptid) LOOP     
    BEGIN
    insert into v_owner.RESULT_TABLE
    END;
    END LOOP;
    END LOOP;How can i pass parameter value of the stored procedure through unix script(that is "owner" in this case), when these parameter value is
    used in cursor? :(
    Can anybody help me regarding the same?
    Thanks in Advance !! :D

    It's not the parameter in the cursor that is the problem, it's that you are trying to use static SQL for something that won't be known until run time (the owner of the table).
    You would need to use something like ...
    declare
       l_owner        varchar2(30) := 'SCOTT';
       l_ref_cursor   sys_refcursor;  
       type l_ename_tab is table of scott.emp.ename%type;
       l_ename_array  l_ename_tab;
    begin
       open l_ref_cursor for
          'select ename
          from ' || l_owner || '.emp';
       loop
          fetch l_ref_cursor bulk collect into l_ename_array limit 10;
          exit when l_ename_array.COUNT = 0;
          for x in 1 .. l_ename_array.count
          loop
             dbms_output.put_line(l_ename_array(x));
          end loop;
       end loop;
       close l_ref_cursor;
    end;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01

  • Passing object references to methods

    i got the Foo class a few minutes ago from the other forum, despite passing the object reference to the baz method, it prints "2" and not "3" at the end.
    but the Passer3 code seems to be different, "p" is passed to test() , and the changes to "pass" in the test method prints "silver 7".
    so i'm totally confused about the whole call by reference thing, can anyone explain?
    class Foo {
        public int bar = 0;
        public static void main(String[] args) {
                Foo foo = new Foo();
                foo.bar = 1;
                System.out.println(foo.bar);
                baz(foo);
                // if this was pass by reference the following line would print 3
                // but it doesn't, it prints 2
                System.out.println(foo.bar);
        private static void baz(Foo foo) {
            foo.bar = 2;
            foo = new Foo();
            foo.bar = 3;
    class Passer2 {
         String str;
         int i;
         Passer2(String str, int i) {
         this.str = str;
         this.i = i;
         void test(Passer2 pass) {
         pass.str = "silver";
         pass.i = 7;
    class Passer3 {
         public static void main(String[] args) {
         Passer2 p = new Passer2("gold", 5);
         System.out.println(p.str+" "+p.i);  //prints gold 5
         p.test(p);
         System.out.println(p.str+" "+p.i);   //prints silver 7
    }

    private static void baz(Foo foo) {
    foo.bar = 2;
    foo = new Foo();
    foo.bar = 3;This sets the bar variable in the object reference by
    foo to 2.
    It then creates a new Foo and references it by foo
    (foo is a copy of the passed reference and cannot be
    seen outside the method).
    It sets the bar variable of the newly created Foo to
    3 and then exits the method.
    The method's foo variable now no longer exists and
    now there is no longer any reference to the Foo
    created in the method.thanks, i think i followed what you said.
    so when i pass the object reference to the method, the parameter is a copy of that reference, and it can be pointed to a different object.
    is that correct?

  • Passing output to a method, I'm lost!

    I want to put all of my "output" including the returns on the three Temp functions in my method DisplayTemperatures, but I'm stuck and don't know how to do this. Please help
    import javax.swing.*;
    import java.text.DecimalFormat;
    public class Temp {
         public static void main(String[] args) {
              int Hourly_Temperatures[];
              String output;
              Hourly_Temperatures = new int[24];
              DecimalFormat twoDigits = new DecimalFormat ("00");     
              for (int i = 0;i < Hourly_Temperatures.length;i++) { //inputs temps               
                   Hourly_Temperatures[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter temperature between -50 & 130\nHour: " + twoDigits.format(i) + ":00"));
                   while (Hourly_Temperatures[i] < -50|| Hourly_Temperatures[i] > 130) {
                        Hourly_Temperatures[i] = Integer.parseInt(JOptionPane.showInputDialog(null,"Invalid Entry!\nEnter temperature"));
              output = "Hour\tTemperature\n"; // build output string
              for (int counter = 0; counter < Hourly_Temperatures.length; counter++)
              output += twoDigits.format(counter) + ":00" + "\t" + Hourly_Temperatures[counter] + "\n";
              JTextArea outputArea = new JTextArea();
              outputArea.setText(output);
              JOptionPane.showMessageDialog(null,outputArea,"24 hour Temperature",JOptionPane.INFORMATION_MESSAGE);
              //System.exit(0);
         } //end main
         public int High_Temp(int Temperatures[]){
              int highTemp = Temperatures[0];
              for (int counter =0; counter < Temperatures.length; counter++)
              if (Temperatures[counter]>highTemp)
              highTemp = Temperatures[counter];
              return highTemp;
         }//end method High_Temp
         public int Low_Temp(int Temperatures[]){
                   int lowTemp = Temperatures[0];
                   for (int counter =0; counter < Temperatures.length; counter++)
                   if (Temperatures[counter]<lowTemp)
                   lowTemp = Temperatures[counter];
                   return lowTemp;
         }//end method Low_temp
         public int Average_Temp(int Temperatures[]){
              int total = 0;
              for (int counter =0; counter < Temperatures.length; counter++)
              total += Temperatures[counter];
              return total / Temperatures.length;
         }// end method Average_Temp
         public void Display_Temperatures(int Temperatues[], int Average_Temp){
        }// end method Display_Temperatures
    } //end class

    I am not sure I understand what problem you are having in passing output to the method. However, I'll guess:
    If you want to pass output to Display_Temperatures() then:
    1. change Display_Temperatures to accept a String
    2. move display code from main to Display_Temperatures.
    3. pass output to Display_Temperatures()
    Display_Temperatures(output)If you want to do all the calculations also in Display_Temperatures:
    1. change Display_Temperatures to accept only 1 arg - int[]
    2. move all the calculations & display code from main to Display_Temperatures
    3. pass Hourly_Temperatures to Display_Temperatures()
    Display_Temperatures(Hourly_Temperatures)If you make these changes then you will encounter some compilation errors. Post them here only after you've first tried to understand and fix them.
    If it is something else you want to do, then you will have to explain it better; at least I've not understood your problem.
    The naming standards that almost all jave professionals follow is:
    1. not to use underscore char ( _ ) in method names; so Display_Temperatures shd be DisplayTemperatures
    2. var names don't have _ char within the name and begin with a lower case; so Hourly_Temperatures shd be hourlyTemperatures
    It is generally a good practice to create an instance of the class in the main() method and write the process code in the instance methods instead of putting all that code in main() itself. Read the [url http://java.sun.com/docs/books/tutorial/]tutorials for this starting from the "Your First Cup of Java".

  • Passing objects to a method.

    Hi,
    I was reading this from a book and puzzled by this suggestion:
    for example:
    public Employee findEmployee(String employeeID);
    This method takes a String specifying a unique employee id and returns the Employee object with that id, null otherwise. Don't pass un-necessary objects to methods, and return the appropriate results.
    Why not passing objects to methods, I found it is convenient to pass objects to methods, why ?
    Thanks in advance !
    Tee

    Of course you can pass objects to methods. A String is also an object.
    The author doesn't say to not pass any objects to methods, only no unnecessary objects. He propably means that you don't need a method likepublic Employee findEmployee(String employeeID, String country)to retrieve the Employee if the employee ID by itself is unique or you don't use the country in the method, to give you an example.

  • Passing paramaters to a method

    I am passing objects to another method.
    I do some changes to them and expect the changed objects to be available in the calling method ( since they are supposedely passed by reference) when the execution is returned to it. However, I don't get the changed objects but rather the old ones, before the method execution.
    Can someone explain?
    Thanks,
    Boris.

    This is an extremely common question. A search through this forum would be very useful to you.
    Java does not pass-by-reference in the same way C/C++ do. When you pass an object to a method, you can change the contents of the object using its methods and see the changes after the method completes in the calling method. In this way Java is similar to C/C++.
    However, you cannot change an object to equal another object or a new object inside a method and expect the changes to be visible after the method completes in the calling method.
    Here is an example.
    This will show changes and the line "String" would be printed.
      StringBuffer sb = new StringBuffer();
      method(sb);
      System.out.println(sb);
      public void method(StringBuffer buf) {
        buf.append("String");
      }However, this would not show changes and the line "Old String would be printed:
      String string = "Old String";
      method(string);
      System.out.println(string);
      public void method(String string) {
        string = "New String";
        // string.concat("New String) would also fail to work

  • Passing parameters to a method

    I am passing objects to another method.
    I do some changes to them and expect the changed objects to be available in the calling method ( since they are supposedely passed by reference) when the execution is returned to it. However, I don't get the changed objects but rather the old ones, before the method execution.
    Can someone explain?
    Thanks,
    Boris.

    I do some changes to them and expect the changed
    objects to be available in the calling methodIf you modify an object passed to a method, then the changes made to that object will be visible as soon as they are made.
    If you change the parameter so that it references some other object, this will NOT be seen in the calling method.
    You can "fake" it by putting the object in question in an array and passing the array. Better though is to just not expect methods to be able to change references they are passed to point at some other object.

Maybe you are looking for

  • Unable execute a BPEL process calling esb db outbound service

    getting the following error while invoking an esb db service from a synchronous bpel process <Faulthttp://schemas.xmlsoap.org/soap/envelope/> <faultcode>env:Server</faultcode> <faultstring>com.oracle.bpel.client.delivery.ReceiveTimeOutException: Wait

  • How can I send multiple photos in an email?

    How can I send multiple photos in an email?

  • Getting error while deploying adf in application server 10.1.2.0.2

    I just pasted log file which is generated while deploying adf in application server 10.1.2.0.2 ---- Deployment started. ---- Dec 15, 2007 10:48:26 AM Target platform is Oracle Application Server 10g 10.1.2 (Unix) (applicatonserverconnection10g2). jav

  • Sending mail

    When I try to send mail this error message appears: This message could not be delivered and will remain in your Outbox until it can be delivered. The server "smtp.sbcglobal.yahoo.com" cannot be contacted on port 25. I am using my AirPort wireless con

  • Iweb site for use with my own hosting company, not .mac

    Hello, What I would like to do is setup a photo album site in iweb but export it to ftp to my own hosting company. I noticed on a link found here that if you do so you lose the ability to have a slideshow......will this effect the ability for a perso