Can one combine static and instance methods?

Hi,
Can one define a method so that is can be used as both a static or an instance method?
Basically I'm trying to simplify my class to so that I can call a method either statically with parameters or instantiated using it's own attributes.
In other words, I'm trying to accomplish both of these with one method:
zcl_myclass=>do_something_static( im_key = '1234' ).
lv_myclass_instance->do_something( ).   " key in private attributes
Why would I want to do that?
I would like to avoid instantiation in some cases for performance reasons and would like to keep it simple by having only one method to do basically the same thing.
Any input or alternative suggestions welcome.
Cheers,
Mike

Ok, I may be reaching here a bit, I know, but maybe this may give you some ideas.  After creating the object, pass it back to the method call.
report zrich_0001.
*       CLASS lcl_app DEFINITION
class lcl_app definition.
  public section.
    data: a_attribute type string.
    class-methods: do_something importing im_str type string
                               im_ref type ref to lcl_app optional.
endclass.
*       CLASS lcl_app IMPLEMENTATION
class lcl_app implementation.
  method do_something.
    if not im_ref is initial.
       im_ref->a_attribute = im_str.
      write:/ 'Do_Something - ',  im_ref->a_attribute.
    else.
      write:/ 'Do_Something - ',  im_str.
    endif.
  endmethod.
endclass.
data: o_app type ref to lcl_app.
start-of-selection.
  create object o_app.
  call method o_app->do_something(
           exporting
               im_str = 'Instansiated'
               im_ref = o_app ).
  call method lcl_app=>do_something(
           exporting
               im_str = 'Static' ).
Regards,
Rich Heilman

Similar Messages

  • Name space conflict between static and instance method

    Hello,
    there seems to be a very unfortunate name space conflict between static and instance method name. Consider:
    static String description() that should return a description of a class.
    String description() that should return a description of an instance.
    That seems to confuse the compiler. How come? Static and instance methods don't have anything to get confused about.
    Thanks for any insights :-)

    Umm...jeez.
    It's not a bug, it's the way it's supposed to be.
    Since a static method can be called the same way an instance method
    A instance = new A();
    A.staticMethod();
    instance.staticMethod();it's not allowed.
    Also in the class, you can call
    public void myMethod() {
          instanceMethodInClass();        // You don't need this, it's superfluous
          staticMethodInClass();          // You don't need the class name.
    }If you didn't understand, then just accept the fact that it is so. Some day you'll understand it.

  • Can't make static reference to method while it is static

    Hello, can somebody please help me with my problem. I created a jsp page wich includes a .java file I wrote. In this JSP I called a method in the class I created. It worked but when I made the method static and adjusted the calling of the method it started to complain while i didnt make an instance of the class. the error is:Can't make static reference to method
    here is the code for the class and jsp:
    public class PhoneCheckHelper {
    public static String checkPhoneNumber(String phoneNumber) {
    String newPhoneNumber ="";
    for(int i=0; i<phoneNumber.length(); i++) {
    char ch = phoneNumber.charAt(i);
    if(Character.isDigit(ch)) {
    newPhoneNumber += String.valueOf(ch);
    return newPhoneNumber;
    <html>
    <head>
    <title>phonecheck_handler jsp pagina</title>
    <%@page import="java.util.*,com.twofoldmedia.text.*, java.lang.*" %>
    </head>
    <body>
    <input type="text" value="<%= PhoneCheckHelper.checkPhoneNumber(request.getParameter("phonenumberfield")) %>">
    </body>
    </html>

    Go over to the "New to Java" forum where that message is frequently explained. Do a search if you don't see it in the first page of posts.

  • Can't make static reference to method

    hi all,
    pls help me in the code i'm getting
    " can't make static reference to method....."
    kindly help me
    the following code gives the error:
    import java.rmi.*;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.io.*;
    import java.io.IOException;
    import java.io.LineNumberReader;
    public class client
    static String vcno;
    static String vpin;
    static String vamt;
    static String vordid;
    static String vptype;
    //static String vreq;
    static String vreq = "1";
    static String vorgid;
    static String vm1;
    static String vs1;
    static String vqty1;
    static String vm2;
    static String vs2;
    static String vqty2;
    static String vm3;
    static String vs3;
    static String vqty3;
    static String vm4;
    static String vs4;
    static String vqty4;
    public static void main(String args[])
    try
    ServerIntf serverintf=(ServerIntf)Naming.lookup("rmi://shafeeq/server");
    int c;
    StringBuffer sb;
    FileReader f1=new FileReader("c:/testin.txt");
    sb=new StringBuffer();
    int line=0;
    while ((c=f1.read())!=-1) {
    sb.append((char)c);
    LineNumberReader inLines = new LineNumberReader(f1);
    String inputline;
    String test;
    while((inputline=inLines.readLine())!=null)
    line=inLines.getLineNumber();
    switch(line)
    case 1: {
    vcno = inLines.readLine();
    System.out.println(vcno);
    case 2: {
    vpin = inLines.readLine();
    System.out.println(vpin);
    case 3: {
    vptype = inLines.readLine();
    System.out.println(vptype);
    case 4: {
    vamt = inLines.readLine();
    System.out.println(vamt);
    case 5: {
    vordid = inLines.readLine();
    System.out.println(vordid);
    case 6: {
    vorgid = inLines.readLine();
    System.out.println(vorgid);
         case 7: {
    vm1 = inLines.readLine();
    System.out.println(vm1);
         case 8: {
    vs1 = inLines.readLine();
    System.out.println(vs1);
         case 9: {
    vqty1 = inLines.readLine();
    System.out.println(vqty1);
         case 10: {
    vm2 = inLines.readLine();
    System.out.println(vm2);
         case 11: {
    vs2 = inLines.readLine();
    System.out.println(vs2);
    case 12: {
    vqty2 = inLines.readLine();
    System.out.println(vqty2);
    case 13: {
    vm3 = inLines.readLine();
    System.out.println(vm3);
         case 14: {
    vs3 = inLines.readLine();
    System.out.println(vs3);
    case 15: {
    vqty3 = inLines.readLine();
    System.out.println(vqty3);
    case 16: {
    vm4 = inLines.readLine();
    System.out.println(vm4);
    case 17: {
    vs4 = inLines.readLine();
    System.out.println(vs4);
    case 18: {
    vqty4 = inLines.readLine();
    System.out.println(vqty4);
    f1.close();
    FileWriter f2=new FileWriter("c:/testout.txt");
    String t;
    t=ServerIntf.add(vcno,vpin,vamt,vordid,vptype,vreq,vorgid,vm1,vs1,vqty1,vm2,vs2, vqty2,vm3,vs3,vqty3,vm4,vs4,vqty4);
    String str1 = " >>";
    str1 = t + str1;
    f2.write(str1);
    System.out.println('\n'+"c:/testout.txt File updated");
    f2.close();
    catch(Exception e)
    System.out.println("Error " +e);

    Yes, ServerIntf is the interface type. The instance serverIntf. You declared it somewhere at the top of the routine.
    So what you must do is call t=serverIntf.add(...)This is probably just a mistype.

  • When i make calls, all i can hear is static, and when i plug in headphones or turn the speaker on, it still doesnt work. but facetime, music, an apps sound still work. help? iphone 5

    when i make calls, all i can hear is static, and when i plug in headphones or turn the speaker on, it still doesnt work. but facetime, music, an apps sound still work. help? iphone 5

    Hello Delaney1130,
    It sounds like you are getting static on both the receiver and the speaker when you make a call. I would use the troubleshooting from the following article to help resolve the issue named:
    iPhone: Troubleshooting issues making or receiving calls
    https://support.apple.com/kb/TS3406
    Toggle airplane mode: Tap Settings > Enable Airplane Mode, wait five seconds, then turn off airplane mode.
    Check your phone settings:
    Check your Do Not Disturb settings: Tap Settings > Do Not Disturb.
    Check for any blocked phone numbers: Tap Settings > Phone > Blocked.
    See if Call Forwarding is turned on: Tap Settings > Phone > Call Forwarding.
    Ensure that your software is up to date:
    Check for a carrier settings update.
    Check for an iOS software update.
    Note: Some updates may require a Wi-Fi connection.
    If the iPhone has a SIM card, reseat the SIM card.
    If the iPhone 4 or iPhone 4s is on the Verizon network, dial *228 from the iPhone and select option 2 to update the Preferred Roaming List (PRL). The PRL determines the cellular towers the phone uses for cellular service, selecting those with the best signal strength.
    Reset the network settings: Tap Settings > General > Reset > Reset Network Settings.
    Try to make or receive calls in another location.
    Attempt to isolate to one network band:
    If you're having the issue on LTE, disable LTE, if possible, and try again.
    If you're having the issue on 3G/4G, disable 3G/4G, if possible, and try again.
    Contact the carrier to check the following:
    Your account is properly configured to use the specific iPhone that has the issue.
    There are no localized service outages.
    Your account doesn't have a billing-related block.
    Your calls don't have errors on the carrier system.
    Restore the phone as new.
    If the above steps don't resolve the issue, go to an Apple Retail Store, carrier, Apple Authorized Reseller, or contact AppleCare to send the phone in for service.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Use two streams to manager client video/audio,Can i combine streams and record it with server AS API

    Use two streams to manager client video/audio,Can i combine streams and record it with server AS API
    I tried Stream.play()
    var s=Stream.get("combine");
    s.play("video");
    s.play("audio",null,null,false);
    s.record("append");
    it's don't work!!

    Thanks, that's what I had thought. Our domain.com zone is sourced internally and replicated to our advertisers for external users, so there's no way to change the result for internal vs external users.
    This is a rudimentary question that I should already know but I sort of inherited this after it was built: Can I have users sign in with their email address ([email protected]) but under the hood, their SIP address is [email protected]? This would let users
    sign in with an address they expect, but it would take advantage of the the local lyncdiscoverinternal record.
    Thanks,
    Matt

  • Static or Instance methods

    Hi,
    I am a self-taught Java programmer and have been writing Java code over the past 18 months. I am comfortable with general coding, but I am having great difficulty deciding whether a method should be static or instance.
    In many cases, I decide to create a class which has maybe 1 or 2 methods. A good example of this is the class I wrote which allows me to pass it a JFrame and it then centres the JFrame on screen. Seems to me I can do 1 of 2 things.
    1. Put the code in the class constructor and then call it with:
    CentreMe cm = new CentreMe(this);
    where CentreMe is the name of the class and this refers to the JFrame that is being passed
    2. Put the code in a static method within the class and then call it with:
    CentreMe.CenterFrame(this);
    Assuming that all the CentreMe class does is to centre a frame in this way, which is the correct (or at least best) approach. Seems to me there is no point in creating objects as per option 1 when they are never used therafter?
    If anyone has advice or a URL that deals with this particular "design" issue I would be very grateful.
    Thanks
    Mark

    Given that design, then your intuition is correct, that method should be static. No need for objects there. But on a higher level, the design is backwards. Instead of having a separate class that knows how to centre a JFrame, it would be better to create a subclass of JFrame that knows how to centre itself. Have a look at Bruce Eckel's online book "Thinking in Java" ( http://www.bruceeckel.com ); it has a lot of useful information about the design of objects.

  • How can I combine Left and Right audio?

    Hi,
    When I record video, one lapel mic records to the left channel and the other records to the right channel in one audio track. I can't seem to figure out how to combine them within Premiere Pro (I've already attempted searching the forums for more info). I know in Sony Vegas you can right click the single audio track and select "Combine" and it will combine the 2 channels so that when people watch the end product you have both voices coming out of both speakers.
    Any help would be appreciated.
    Thanks
    Kelly G.

    Hello,
    Yes i have the same issue.
    I use the duplicate Audio track and fill left and right all the time.
    when i am doing Interview videos i usually have one person on channel 1 and the other on channel 2 and it comes out as L and R in Premiere.
    Today i was shooting with myself on Channel 2 and a shotgun for some ambient sound on channel 1.
    In Vegas or FCP 7 there is a simple effect to drag and drop called " Combine" that nicely combines the L and R channels each into stereo.
    I used to use it quite a bit and think it would be a great addition to Premiere Pro.
    So i am wondering several years since this was first post if Premiere does in fact now have this option...and where it might be that i over looked it?
    If not.....is there an easier way to do this than the fill left and right method?
    Thanks so Much!
    Mark

  • A single report can't combine portrait and landscape oriented pages

    Post Author: joelo2
    CA Forum: Crystal Reports
    Hi,
    Can a single report in Crystal report XI (version 11.5.8.826) combine portriat and landscape oriented pages like Crystal report 2008?   For example, I have one main report with several subreports in the main report.  I want one subreport be in portrait page orientation and the other subreports in landscape.  Can I do something like that in Crystal report XI version?    I even tried writing a small .net program to do this, but it doesn't seem to allow me to do that programmatically either.  Please help

    Post Author: ngra
    CA Forum: Crystal Reports
    I'd like to elevate this issue with Crystal Reports XI. There is a critical application which we developed in-house which needs both portrait and landscape orientation in each of the 30,000 plus documents we are sending out every month.If developers in Business Objects are picking this thread up - we need a patch for this limitation - quick. Right now, we are toying with the possibility of exporting the documents into a text format with markers indicating if a page is portrait or landscape. This is to be loaded into a Xerox machine (which costs hundreds of thousands of dollars), where it is mapped automatically to portrait or landscape. Note to Business Objects: This will provide us and countless others with much value. Think 80/20 rule - most bang for your development bucks and value for your customers!

  • Objects and instance methods for JSP?

    I've been looking through the JSP 2.0 specification and, while I'm extremely impressed with the improvements in this version, I'm also disappointed to see that everything still boils down to statically bound methods.
    What I mean by this is that the template part of a JSP is like an anonomously named static method associated with the JSP class. The new tag-files in JSP 2.0 are terrific, but they also have this same kind of static binding.
    As far as I know, only JPlates (www.jplates.com) allows you to develop web applications using actual instances of classes that have instance methods for expressing the template parts. Are there any other template processing systems that support real object-oriented development of dynamic content-generation applications?

    By an amazing coincidence, the domain name jplates.com is registered to a Daniel Jacobs and your user name is djacobs. What are the odds of that?
    If you're going to plant commercials, you need to disguise them better than this.

  • How can one transfer emails and contacts from Zimbra to gmail, without it being deleted if the Zimbra account is shut down?

    How can one move Zimbra Contact list and emails to a gmail account, so they won't be deleted if the Zimbra account is shut down?

    What does this have to do with iPhones or anything else Apple related.  Contact Zimbra and ask them...

  • How can one record live and simulatoneously show what is getting recorded?

    hello friends
    how can one record live video and simulatoneously show what is getting recorded?
    please help?
    Manmeet

    i have found solutions
    thanks

  • LR 1.4.1 - Can I combin catalog and make as one?

    I working on LR 1.4.1 and when I first started useing it I just used it ,now I would love to combind some of my old catalogs into one for ease of work flow.
    Is able to be done?
    Thanks

    RICHARD RODAMAR had this to say:
    I working on LR 1.4.1 and when I first started useing it I just used it ,now I would love to combind some of my old catalogs into one for ease of work flow.
    Is able to be done?
    You should be able to IMPORT CATALOG, yes. This will add the contents of
    the old catalog to the currently opened catalog. I've never had to do
    it, but it's supposed to Just Work.

  • With regex, how can I combine backreference and repetition

    Let's say I have a four byte long input string, consisting of four hex values:  0x03 0x03 0x03 0x03
    If I use repetition in a regex string pattern: .{4}  it matches true.
    Also, if I use backreference in a new regex pattern: (.)\1\1\1  it matches true.
    But I want to combine the two.  Say that the first byte is a length byte of the following bytes.  Then I'd believe it should be possible to do this: (.).{\1}
    The thought is that the first byte is stored as "variable" \1, and reused as the repetition counter.  So in this case, all four byte strings starting with 0x03 should match true.
    But this doesn't work!
    What am I doing wrong here?  Is this just not possible?

    ojohnsen wrote:
    No RegEx experts here?
    I am not an expert, but I play one on this forum.  To show something is possible is quick, since you can demonstrate it.  To show something is impossible is a bit harder.  For now I say, not possible.  And you do realize that .{4} will match any four character string, not anything repeated four times, right?
    That said, it sounds like you know the format of your string, so perhaps a regex would not be your first choice.  You could split a string, read the first byte, then construct a regex like ^(.)\1{length-1} and see if the remainder of the string begins with a value repeated length times.

  • Can I combine 'sets' and 'stacked' charts?

    Hi all
    I want to create a column chart in Numbers which combines sets (which I understand to be connected columns grouped together) with stacks (one or more columns split into smaller parts).
    Is this possible?
    Thanks!     : )

    To the best of my knowledge there is no chart that has a combination of stacked columns and sets. You can make two (or more) stacked column charts, make some adjustments and settings and put them together.  It takes a few steps to do it right. Below is an example that needs some more work. I set the Y axis min and max to the same values for both charts. Same vertical and horizontal size for both charts, adjusted the gap between sets to be 140%, moved the legends so they didn't overlap, removed the Y axis value labels for the chart that is furthest to the right, changed colors on the chart furthest to the right. I didn't know what to do about the X axis labels. If you have an even number of sets you might have to turn them off and put a one-row table there to replicate the labels. If you have an odd number of sets, you could use the labels from the center set and turn the rest of them off.

Maybe you are looking for

  • Forwarding JSP page through requestdispatcher problem in submiting form

    Hello everyone, I am very much new to servlet. My problem is somewhat this.... when i am forwarding one JSP page by requestdispather , there is no problem.But after that when i am trying to submit one html form written inside the jsp page , the reque

  • Baffled

    hi here's a segment of code i'm having a problem with : import java.io.*; public class Reader_O {   public static int reader() throws IOException{     BufferedReader d = new BufferedReader(new DataInputStream(System.in));      String input;     while

  • No video in iMovie 5.0.2

    For some reason, when I am importing .mov videos (VERY low quality), the screen is just white and it only plays the audio. Can someone help? Thanks.

  • Connectin to oracle db at localhost

    hello i use ado to connect oracle 10 g database at localhost ... i use oracle's provider... what is the technology for conection to db on localhost -network, shared memory, local procedure call ? please help

  • Calling two Business service using split join in osb

    Hi, While trying to call two business service using Split Join in osb i am getting selection failure message in Bpel em console. i am using invoke activity to invoke the BS and assign to assign the input. in the assign i am assigning *$request.payloa