Ho to make Method name as a variable???

does anyone know how i can call a method whose name
is determined dynamically? for instance, if i have two
methods:
public void method0(){
public void method1(){
and i want to call the method based on the value
of x (without using an if statement), can i do
so? in other words, instead of calling method0()
or method1(), can i call, so to speak, methodx(),
which, if x is 0, will call method0() and, if x
is 1, will call method1()?

I can think of situations where you might want to use that. For me it would be a speed issue, although I don't think it'll be faster with reflection.

Similar Messages

  • Variable/method names standardizing

    Hi All,
    The problem we've got here is that same things are named in slightly different way by different developers or development groups.
    Typical example:
    'id' property. accessors could be named like: 'getID' or 'getId'.
    Or even better example: term 'Work List' implementation of which has nothing to do with Java List. So, property could be named as 'worklist' or 'workList' with similar names for accessors.
    I think, this problem is slightly outside of coding standards scope. And as project is very massive ~300000 lines of code, there are a lot of different terms named like in example above.
    Has anyone come across such problem before?
    I suspect, solution would be to keep a kind of variable/method names library.
    Are there any better solutions?
    Thanks in advance
    Andrei

    I think, this problem is slightly outside of coding
    standards scope. It is, and I'm glad it is because the "people" who make the standards that we do have end up creating dumb, inconsistent stuff as it is. Better they don't get too granular.
    Has anyone come across such problem before?Every day
    I suspect, solution would be to keep a kind of
    variable/method names library.
    Are there any better solutions?How you name stuff is a matter of opinion. I personally don't care if you do someID or someId or even someid, what kills me is stuff like someid and someid. But again, it's all what you're used to.

  • SSDT vs 2013 and Clr function, call a Clr method name dynamically using SQLCMD variables

    Hello,
    My question is this, hopefully this makes sense:
    How could I got about doing this, inside a SQL function, I would like to re-name the Clr method call based on a SQLCMD variable? 
    I have a Clr project to encrypt/decrypt data, there are different method names depending on the deployment types.
    For the definition of a function called dbo.EncryptThis, I would like to use a SQLCMD variable to change the name depending on SQLCMD variables. This works fine in SQL Server Mgmt studio, but VS 2013 fails to recognize the SQLCMD variable and the build fails
    with: "Error
    1
    SQL71521: A method with a matching signature was not found in the loaded assembly.".
    THis code works fine in SQL Server Mgmt Studio, but fails to build in the SSDT project.
    In the SSDT project I have the SQLCMD variable defined and think I have SQLCMD mode enabled, by doing this:
    Right click file > Execution Settings > SQLCMD mode
    CREATE FUNCTION [dbo].[EncryptData]
    (@str NVARCHAR (MAX))
    RETURNS NVARCHAR (MAX)
    AS
    EXTERNAL NAME [CryptoClrAssembly].[LibName].[EncryptData$(MethodName)]
    Is this even possible in SSDT? or would I have to do this in a post-deploy script?

    Hi Kevin,
    Thanks for the info.
    Bummer, so the only other solution I have is to create a post-deploy script to change the function based on a SQLCMD variable or other logic?
    What would be really cool, would be if during the build process the SQLCMD variables would get replaced with the default value to the SQLCMD variable, thus would allow to build the project. Also, during deployment, if someone entered an incorrect method
    from the assembly it would just fail.

  • How to convert a String variable as class name and method name?

    i have two classes
    class Student
    public String insertStudent(String sname)
    { return("Student has been inserted ");     }
    class Teacher
    public String execute(String methodName, String className)
    {  //return statement of the method 'insertStudent' in the class 'Student'; }
    }Now, i have a class with the main method. Here, i would like to call the method *'insertStudent'* of class *'Student'*
    using the method *'execute'* of class *'Teacher',* passing the method-name and the class-name (viz. insertStudent, Student) as the
    String parameter.
    Can anyone please help me out. Thanks
    regards,
    chinglai

    You should have just added that as a comment on your [initial posting|http://forums.sun.com/thread.jspa?threadID=5334953] instead of starting a new thread.
    Now, i have a class with the main method. Here, i would like to call the method 'insertStudent' of class 'Student'using the method 'execute' of class 'Teacher', passing the method-name and the class-name (viz. insertStudent, Student) as the
    String parameter.
    Why oh why? What do you want to achieve?
    Let me tell you: there is a way to do what you try to do, but it's not recommended and should be used only very sparingly. Especially not in anything like your code, that resembles normal business logic (as opposed to an application framework such as Spring, for example).
    Can you explain what exactly you want to do with that? Why should a Teacher be able to call any random method ony any other class. And what good would that do?

  • How to make the name of a column apear as many times as the column on page

    Hi,
    This is what i want to do:
    I have a basic report looking like this:
    <Column name>
    value 1
    value 2
    value 3
    value n
    Since the column is small it can fit in a page more then one time. I know how to make it print more then once: i switch the repeating frame to print down and across and i modify the frame that contains it so the horizontal elasticity is variable.
    After these changes my report looks like this:
    <Column name>
    value 1-----------------------value n+1-----------------------value m+1
    value 2-----------------------value n+2-----------------------value m+2
    value 3-----------------------value n+3-----------------------...
    value n-----------------------value m
    What i want is my report to look like this:
    <Column name>-------<Column name>------------<Column name>
    value 1-----------------------value n+1-----------------------value m+1
    value 2-----------------------value n+2-----------------------value m+2
    value 3-----------------------value n+3-----------------------...
    value n-----------------------value m
    Would welcome any advice on how to achieve this please.
    Thank you.

    Hi,
    I will suggest a solution which may appear not simple. I do not know. Il did use this method, because a Government pre-printed tax form can print six values (in colum way) each page and it was not just esthetique question.
    1. Seams that you can know in advance the max number of column according to the width of the page and the length of the column.
    2. You can assume that you have x column at max by ligne
    3. Transforms your N rows in a table of M rows, each one with x columns : you will have N/x + N mod x
    4. I did this transformation using PL/SQL piplined function to transform rows to columns (by x)
    5. You base your report on the Pipelined function using select ... from Table (fnc_....) syntaxe
    6. make your vertical elasticity to variable and horizontal to fixed
    7. Put six labels on the top of your repeating frame (within a normal frame)
    I agree, it's not the solution if the requirment is just esthetic.
    Hope it helps.
    Mohamed Dadi

  • Variable name that is variable?

    Guys,
    I want to create distinct/different menus using my dynamic gui generation program.
    The thing is, I need the menu object to be of a different name each time I want to create a menu.
    code snippet:
    Menu menu;
    menu.add( blahcomponent);
    I want the menu object to be different each time,
    eg,
    menu1.add( blah);
    menu2.add(blah);
    menu3.add(blah);
    How can I make it so that the variable "menu"
    is distinct each time?
    I am thinking of concatenating strings together to create different variable names but this doesn't work as it isn't possible to convert String to a Menu obj?
    eg,
    menu = "menu".concat(id); // where id is a String                     // variable
    menu.add(blah);
    I hope you get my idea. Any help/alternative
    solutions highly appreciated.

    You can use a string as the key to the hashtable, look at the API, the get(key) method accepts an object as the key. also, if you are looking up by index only, a hashtable is not faster than an array, as they accomplish the same look up task (this to earlier post). If your using strings as keys, a hashtable would be better here though.

  • How to make use of the presentation variable in SQL result query

    I have 2 prompts in my dashboard.
    Prompt1 decides the values of Prompt2.
    I have set a presentation Variable (selected_comp) in prompt1 which holds the value selected.
    To populate the values for Prompt2, I need to execute a query using the presenation variable set by Prompt1.
    SELECT "List Of Values".RID from rocketv2_3 WHERE "List Of Values".NAME='COMPONENT' AND "List Of Values".VAL=@{selected_comp}
    the query is resulting into
    SQL Issued: SELECT "List Of Values".RID from rocketv2_3 WHERE "List Of Values".NAME='COMPONENT' AND "List Of Values".VAL=0
    but the value in selected_comp is "ABC".
    Can anybody help in how to make use of the presentation variable in query to get the correct value
    thanks
    Shubha

    Just use constrain check box to filter your 2nd prompt values based on the 1st prompt.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • Failed to parse method name:

    Hi,
    I've the following environment:
    - Sun Solaris
    - WL 61 without service pack
    - jdk 1.3.1
    I wrote a simple Session Bean and make it IIOP enabled.
    For the Java-Corba client I use an IDL which describes
    the interfaces of the remote and home interface of the
    Session Bean.
    Everything works fine, that means I get the WL's NameService,
    home and the remote object. If I call a method of the remote
    object I got the following message:
    <Info> <IIOPEndPoint> <failed to parse method name: foundUnkownSubscriber>
    I found something in you newsgroup and you said the we should
    use SP2. Where can I get this SP2?
    Regards
    Andre Genser

    Andy Piper <[email protected]> wrote:
    "Andre Genser" <[email protected]> writes:
    I've the following environment:
    - Sun Solaris
    - WL 61 without service pack
    - jdk 1.3.1
    I wrote a simple Session Bean and make it IIOP enabled.
    For the Java-Corba client I use an IDL which describes
    the interfaces of the remote and home interface of the
    Session Bean.
    Everything works fine, that means I get the WL's NameService,
    home and the remote object. If I call a method of the remote
    object I got the following message:
    <Info> <IIOPEndPoint> <failed to parse method name: foundUnkownSubscriber>Are you sure you are spelling correctly? Seems like this should be
    foundUnknownSubscriber.
    andy
    -- Sorry Andy, it was the name but I didn't solved the problem. Now I got the following
    exception:
    <Apr 16, 2002 8:47:29 AM CEST> <Warning> <Dispatcher> <Error thrown by rmi server:
    'weblogic.rmi.cluster.ClusterableServerRef@111 - jvmid: '-5101001595216439928S:10.2.9.70:[8045,8045,9045,9045,8045,9045,-1]:agenser8045:myserver',
    oid: '273', implementation: '[BaseEJBObject] home: prototype.CallBackBean_w4a7u3_HomeImpl@29bced''
    java.lang.OutOfMemoryError
    <<no stack trace available>>
    >
    <Apr 16, 2002 8:47:29 AM CEST> <Error> <Kernel> <ExecuteRequest failed
    java.lang.OutOfMemoryError
    <<no stack trace available>>
    >
    What is wrong in my solution? Here is my simple IDL-File:
    module prototype{
         exception CallBackException {
         interface CallBack {
              void foundUnknownSubscriber( in string MSISDN) raises(CallBackException);
         interface CallBackFactory {
              CallBack create();
    Thanks.
    Andre

  • Name of ODI variable in the result of Oracle SELECT

    Hello,
    I seek to evaluate the contents of an ODI variable (VP) which is the result of SELECT with other ODI variables (V1, V2,…, Vn) in its contents.
    Currently, the result of this first variable (VP) returns the name of the variables (V1 to Vn) and not the value of these variables.
    For example :
    My variable VP is a select from oracle (SELECT FIELD_NAME FROM TABLE_NAME WHERE XXX = VALUE)
    The field FIELD_NAME contains "The #PROJECT.V1 is OK and the #PROJECT.V2 is KO".
    I want to replace the two variables by their values.
    Does there exist simple means of recovering the value of these variables instead of their names ?
    Else, do you have a solution of skirting knowing that there can be several variables (V1 to Vn) and that they can be different according to the cases ?
    I'm in ODI 10.
    Thank you in advance for your assistance,

    Thanks for your answer.
    The second solution isn't possible to us because we don't know which variables are included in the SELECT result. We can have many variables and it is not always the same variables.
    For the first solution, I try to find the link between the data of table SNP_VAR_DATA and a session (SESS_NO). Unfortunately, I do not arrive there.
    Can you how make ? And by which tables of ODI ?
    Thanks in advance,

  • How to Make SelectedItem be a Dynamic Variable?

    Hi,
    My client wanted me to create something that allows certain
    DataGrid to display to allow users to edit and update the database
    records. The only dilemma I am having here is how to actually
    create something from Flex's end to allow users update several rows
    of the database at once. Since everything in my HTTPService is in
    DataGrid, how can I get Flex to recognize each of the updated
    variables while I update the database? I tried using dg.
    .id in my code, but I kept getting errors that say it is not
    defined. Is there some way where I can make selectedItem be a
    dynamic variable?
    Thanks in advance.
    Alice
    This is the current code I have:
    Attach Code:
    <mx:HTTPService id="save_scenario" method="POST" url="
    http://localhost/save_scenario.php"
    useProxy="false">
    <mx:request xmlns="">
    <scenario_name>{scenario_name}</scenario_name>
    <id_no>{dg.selectedItem.id}</id_no>
    <region_name>{dg.selectedItem.region_name}</region_name>
    <population>{dg.selectedItem.population}</population>
    <market>{dg.selectedItem.market}</market>
    </mx:request>
    </mx:HTTPService>

    "alice_data" <[email protected]> wrote in
    message
    news:ggen1o$a3c$[email protected]..
    > Hi,
    >
    > My client wanted me to create something that allows
    certain DataGrid to
    > display to allow users to edit and update the database
    records. The only
    > dilemma I am having here is how to actually create
    something from Flex's
    > end to
    > allow users update several rows of the database at once.
    Since everything
    > in my
    > datagrid would be defined as selectedItem whenever a
    user accesses the
    > entry,
    > how can I get Flex to recognize each of the updated
    variables while I
    > update
    > the database?
    Add like an updated property to each item in the collection.
    Then set it
    when the user has changed something. Then filter the
    collection to items
    that have been updated and send them to the server.

  • Encryption of body's first child (method name) in Doc Literal Wrapped

    G'day all,
    I created a sample, where the service requires an encrypted input element (body's first child), which is the method name in document literal wrapped web services.
    I added few more operation to the SEI to make it more interesting scenario. It worked rightly.
    I am curious to know how WebService engine picks the security policy rightly? Since the on the wire shows EncryptedData element instead of input message name.
    Also, I added @Policy annotation description on the Impl Class level. Is it going to work or fail if I add different @Policy annotations to each WebMethod level and have encryption of the input element?
    With Regards,
    Mayank

    Hi
    The following link has information on using the Policy annotations
    http://edocs.bea.com/wls/docs100/webserv_sec/message.html#wp210258
    Ajay

  • Extracting method names from JNI probes

    Hello.
    I would like to use the Call* probes from the hotspot_jni provider. These probes provide as argument a "method id". My question is how I can extract, for instance, the method name from this ID. I saw that JNI provides a method "GetMethodName" but being a dtrace novice, I am unsure how to obtain a handle to the JNI api from within dtrace.
    Any hint would be greatly appreciated.
    Best wishes,
    Eric

    Actually, it can be done. Otherwise, how do you think debugger shows variables and formal parameters?
    You should compile your aplication with debuginng information (for details see tools doc). Then you have 3 options:
    1) run application under debugger and use JVMDI to get everything you want;
    2) use bytecode libraries (BCEL, CGLib etc) to read class file and fetch required information through their API
    3) write your own class file parser based on class file format described in Java Virtual Machine Specification
    First way is quite complex and is definitely not for "production use".
    Second way is the best in case you have time limitations, but size of your application will be increased because of thrid-party libraries.
    Thrid way is the best if you have application size restrictions and have enough time to write simple class file parser to fetch that specific information (1-2 days depending on your experience).
    Have fun ;)

  • Using oc4j to generate interfaces from wsdl produced improper method names

    The method names that were produced from the opperations in my WSDL, generated an interface file with incorrect method names. The name went from "DoTest" in the wsdl to "doTest" in the Interface file.
    I double checked and all the cases are correct in the wsdl.
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by John Reynolds (MedPlus) -->
    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:y="http://localhost/TestService" targetNamespace="http://localhost/TestService">
         <types>
              <xs:schema targetNamespace="http://localhost/TestService" xmlns="http://www.w3.org/2001/XMLSchema">
                   <xs:element name="Tresult" type="xs:string"/>
                   <xs:element name="Tname" type="xs:string"/>
                   <xs:element name="Tfault" type="xs:string"/>
              </xs:schema>
         </types>
         <message name="DoTestResponse">
              <part name="Result" element="y:Tresult"/>
         </message>
         <message name="DoTestRequest">
              <part name="Name" element="y:Tname"/>
         </message>
         <message name="DoTestFault">
              <part name="ExceptionDetail" element="y:Tfault"/>
         </message>
         <portType name="TestService">
              <operation name="DoTest">
                   <input message="y:DoTestRequest"/>
                   <output message="y:DoTestResponse"/>
                   <fault name="DoTestException" message="y:DoTestFault"/>
              </operation>
         </portType>
         <binding name="TestService" type="y:TestService">
              <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
              <operation name="DoTest">
                   <soap:operation soapAction="urn:#DoTest" style="document"/>
                   <input>
                        <soap:body use="literal"/>
                   </input>
                   <output>
                        <soap:body use="literal"/>
                   </output>
                   <fault name="DoTestException">
                        <soap:fault name="DoTestException" use="literal"/>
                   </fault>
              </operation>
         </binding>
         <service name="TestServiceSoap">
              <port name="TestService" binding="y:TestService">
                   <soap:address location="http://localhost/TestService"/>
              </port>
         </service>
    </definitions>

    Obviously one could rename the operation to that standard, but that doesn't exactly strike me as being anything other that a work around for a bug.
    WSDL provides a contract in which multiple languages have to conform to a set of interfaces, and it's not exactly good to have a tool, just a assume the contract for an interface is wrong.
    I could argue that I'm only doing Java on the front end and .Net on the client side and that they don't neccessarily follow the Java convention, nor should be constrained by it.
    I do agree with you that they probably just followed the convention when writing to code generator and just happened to pick up the convention. They just need to fix it now.

  • Is it possible to use a variable in the name of other variables?

    Trying to avoid a long post; is there some command in Java that would allow a variable to be read before the rest of the statement it is in?
    For example, using a pair "@" to encapsulate a variable with the mystery command I'm looking for:
    *public class Example {*
    *public static void main (String[] args) {*
    Char variable = "A";
    int @variable@_Status = 0;
    So that this application would create an integer named "A_Status" and assign it a value of 0. Obviously, I'm not looking to be told that "int A_Status = 0" is the best way to do that, I'd like "variable" to be able to be defined by input or change somehow in the code. I have a gut feeling that this is impossible due to the compiler, but I'd like a more professional opinion. Anyone?

    The variable "name" is a lot less important than you think. In fact, when your code is compiled, the computer doesn't care one jot about the name of the variable.
    You should not worry about trying to do this, but rather should tell us the reason why you would even want this. If we knew that, we could show you a better way, guaranteed.

  • Using a variables value as the name of another variable

    Hi, i'm new to java and i've been trying to write a little program. I was wondering whether it is possible to use the value of a variable as the name of another variable.
    This is what i have so far: When i run my java program numerous Animal objects are created with names like ani01, ani02, ani03. These objects have functions like getName() etc. When i type in one of these codes into the command line it gets stored in a variable called 'input'. Everything's fine up to here.
    But i need a way to access the correct Animal from my input. instead of doing countless switch statements on the input.
    If i type "ani02" i want it to return the animals name by calling ani02.getName()...
    how do i do this? i'd appreciate any help. thanks.

    If you were doing this based on user input, then you
    wouldn't have to do a lot of typing. Mmm?I'm sorry i don't get your meaning... ? I am doing this based on user input am i not?
    All i want to do is access the correct Animal object depending on the user's input... so if they type in ani01 it would return 'Elephant' (or whatever) using ani01.getName().
    Maybe i'm going about this the wrong way or something?.. I have about 30 animals. they each have a name, continent, quantity. I have an Animal class that has functions like getName(), setName() etc. When the program starts, 30 objects are created
    Animal ani01 = new Animal("Elephant",3000,"India");
    Animal ani02 = new Animal("Panda",200,"China");etc...
    I want to be able to get information about any one of these animals by typing something at the command line...
    so i type in something (i just thought the name of the object would be the best thing to type in) and i get the info about elephants (or whatever) from the relevant object.
    how would you do this?

Maybe you are looking for