"this." inside classes

Can any one say, if i should use "this." inside my classes to
refer class
variables and methods? What is its advantage and
disadvantage? Does this
help compiler/flash player in any way.
Provide some useful links which explain this
Cheers,
Sajeev

when it's appropriate you can use "this". so, if you've just
created a movieclip and you're defining a mouse handler for it,
it's appropriate to use this within the handler's scope.
but to refer to a class member, i use a private variable in
the constructor function to use throughout the class so i don't
have scope issues outside the constructor function.

Similar Messages

  • Field symbols inside class

    Is it possible to declare field symbols inside classes?
    Thanks in advance.
    Hema
    Moderator message: please search for information and try yourself before asking.
    Edited by: Thomas Zloch on Dec 23, 2010 10:55 AM

    Hi Hemalatha,
    We can use Field Symbols in classes.
    local field_symbols within methods are allowed.
    you can only use field-symbols within method (locally), not as direct class attribute (globally).
    U can check with this sample code.
    Sample code is given below:
    CLASS c1 DEFINITION.
    PUBLIC SECTION.
    METHODS m1 IMPORTING oref TYPE REF TO object attr TYPE string.
    ENDCLASS.
    CLASS c1 IMPLEMENTATION.
    METHOD m1.
    FIELD-SYMBOLS <attr> TYPE ANY.
    ASSIGN oref->(attr) TO <attr>.
    WRITE <attr> ...
    ENDMETHOD.
    ENDCLASS.
    I hope u got this .....

  • Wrong class name inside class file

    Hi@all!
    I wrote a normal applet, and there are no compiling errors.
    But if I try to run it in my netscape 4.77 following exception occurs:
    >>
    Applet exception: error: java.lang.ClassFormatError: Wrong class name inside class file
    >>
    Does anybody know, where the problem is?
    Please help!!!!!
    Thank you!

    I'm not sure but here's a couple ideas. If the class is a public class, then the name of the .class file and the class must be identical and remember that java is case sensitive. Second thought is a class that is defined to be part of a package must reside in a directory that matches the package name.
    If you post more info, you might get a better answer.

  • Static methods inside class in jsp can't make it work

    Hello all i can't understand it why i can't declare the method as static method ?
    public class Request{
              Request(){}
              private String paramValue;
              public static String getRequestParam(HttpServletRequest request, String paramName, String defaultValue){
                   paramValue = request.getParameter(paramName);
                   return paramValue != null ? paramValue : defaultValue;
    im geting this error :
    The method getRequestParam cannot be declared static; static methods can only be declared in a static or top level type
    can't i do inner class ?
    or other sulotion for me not to make instences of class's but to use the class static methods?

    Hi, try this:
    public class Request{
              Request(){}
              private static  String paramValue;
              public static String getRequestParam(HttpServletRequest request, String paramName, String defaultValue){
                   paramValue = request.getParameter(paramName);
                   return paramValue != null ? paramValue : defaultValue;
          }it should work. the problem in you code is that you are trying to referance an non-static object with a static one!
    Message was edited by:
    Adelx

  • Can anyone help me with this test class

    hiya im new to java im trying to make this test class but i comes up with this error
    EmployeeTestClass.java:14: cannot resolve symbol
    symbol  : constructor Employee  (java.lang.String,java.lang.String,java.lang.String)
    location: class Employee
         Employee Test = new Employee ("John", "Henry", "Monthly");
                                ^here is my whole code to the test class, please bear in mind im really new to java
    public class EmployeeTestClass
       public static void main(String[] args)
         System.out.println ("Please type the employee name:");
              String fName = EasyIn.getString();
         System.out.println ("Please type the employee secound name :");
              String sName = EasyIn.getString();
         System.out.println ("Please type the employee eReference :");
              String  eReference = EasyIn.getString();
         System.out.println ("Please type the employee annualSalary :");
              String  annualSalary = EasyIn.getString();      
         Employee Test = new Employee ("John", "Henry", "Monthly");
       Test.showDetails();
    }

    // your code:
    Employee Test = new Employee ("John", "Henry",
    "Monthly");What you need to do is put the
    variables fName, sName etc. in there instead. And you
    declared the variable annualSalary as a
    String, which should be a double.hiya i tried the above and now my code code like this
    public class EmployeeTestClass
       public static void main(String[] args)
         System.out.println ("Please type the employee name:");
              String fName = EasyIn.getString();
         System.out.println ("Please type the employee secound name :");
              String sName = EasyIn.getString();
         System.out.println ("Please type the employee eReference :");
              String  eReference = EasyIn.getString();
    System.out.println ("Please type the employee salary :");
              double  annualSalary = EasyIn.getString();
    Employee Test = new Employee ("fName", "sName", "annualSalary");
       Test.showDetails();
          }but wheni try to complie it it comes up with these error please help
    EmployeeTestClass.java:12: incompatible types
    found   : java.lang.String
    required: double
    double  annualSalary = EasyIn.getString();
                                                              ^
    EmployeeTestClass.java:15: cannot resolve symbol
    symbol  : constructor Employee  (java.lang.String,java.lang.String,java.lang.String)
    location: class Employee
    Employee Test = new Employee ("fName", "sName", "annualSalary");
                         ^
    2 errors

  • How to create Multiple instances of This SingleTon class

    import java.io.*;
    import java.util.Properties;
    import java.net.URLEncoder;
    public class ddd
              // declaring variables
              static private ddd _instance;
              String connectIP;
              int connectPort;
              String systemID;
              String password;
         String systemType;
              // Constructor with arguments
              private ddd()
              globalInit();
         // method returning the ddd instance.
              public static      synchronized ddd getInstance()
              if (_instance == null)
                        _instance = new ddd();
              return _instance;
              // Global initialisations
              public void globalInit()
              systemID ="XXXXX" ;
              password ="XXXXX";
              systemType ="Null";
              public static void main(String[] args)
                   ddd sb;
                   sb = ddd.getInstance();
                   System.out.println(ddd.getInstance());

    Don't cross-post:
    http://forum.java.sun.com/thread.jsp?thread=547911&forum=54&message=2669925
    http://forum.java.sun.com/thread.jsp?thread=547912&forum=31&message=2669928
    Sorry, I can't help but think that this is one of the more foolish questions I've read in a while.
    The pattern Singleton means "I only want one of these in a single JVM". If you want multiple instances, or even a restricted number of instances, then rewrite the class (something like this):
    public class LimitedEdition
        public static final int MAX_EDITIONS = 3;
        private static int numEditions;
        public static void main(String [] args)
            try
                if (args.length > 0)
                    int numEditions = Integer.valueOf(args[0]).intValue();
                    for (int j = 0; j < numEditions; ++j)
                        LimitedEdition limited = new LimitedEdition();
                        System.out.println(limited);
            catch (Exception e)
                e.printStackTrace();
        public LimitedEdition() throws InstantiationException
            if (numEditions < MAX_EDITIONS)
                ++numEditions;
            else
                throw new InstantiationException("Only " + MAX_EDITIONS + " instances allowed");
        public String toString()
            return "[ instance # " + numEditions + "]";

  • I have an ipod nano and its fall down , the inside screen is broken..... can APPLE replace this(inside screen)???!

    i have an ipod nano and its fall down , the inside screen is broken..... can APPLE replace this(inside screen)???!

    Hello Alia A,
    Sorry to hear about your iPod nano screen.  I recommend reviewing the following link for service options (you can update the country selection to your location after accessing the link):
    Service Answer Center - iPod
    http://support.apple.com/kb/index?page=servicefaq&geo=United_States&product=ipod
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • How to call a Screens modules inside class methods in ALV of OOABAP.

    I have a urgent reruirement to call a screen's PBO and PAI module inside a class method. I really dont want to create a function module and call the the screen inside that. Please revert if anyone have a solution as it is really urgent!!
    Moderator message - "Urgency" is not catered to in the forums.
    Message was edited by: Suhas Saha

    Hi Shehzad,
    SAPHELP on Advantages of ABAP Objects - Using ABAP - SAP Library says -
    There are only two purposes for which procedural ABAP is essential:
    · Encapsulation of classic screens in function modules.
    · When you want to make functions available to other systems, but are not able to make class methods available externally using XI server proxies. In this case, you have to use function modules.
    Regards,
    DPM
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/56/14934259a5c66ae10000000a155106/content.htm

  • Load a class inside class?

    Hi all!
    I am creating a console based program and I wonder how i can load an outside class inside my main class?
    I have a case switch funktion and when you chosse case '3' i want the class to run another class file and the continute with the rest of the code in the main class file.
    Is there a way to do this?

    It really depends on what you mean by "run another class file". Do you mean you want to execute its static main() method, just as if it were run from the command line? If so then just do this:String[] params = // the parameters you want to pass to the class
    TheClass.main(params);

  • Php function inside class

    Hello,
    I'm trying to add some custom functions to one class, but I
    got one debug error and I can't discover how to supress this
    using this piece of code inside fpdf class
    $this->pages[$n]->SetMargins(20,47,20,20);
    $this->pages[$n]->rodape_continuado('', 7.5, 240, 117);
    $this->pages[1]->SetMargins(20,47,20,20);
    $this->pages[1]->rodape('', 7.5, 270, 117);
    I got on browser this
    Fatal error: Call to a member function SetMargins() on a
    non-object
    the goal is to make all my pages look equal, and then just
    change the first one
    how can I do this?
    many thanks in advance

    Why not just set these things through a stylesheet?
    Pluda skrev:
    > Hello,
    >
    > I'm trying to add some custom functions to one class,
    but I got one debug
    > error and I can't discover how to supress this
    >
    > using this piece of code inside fpdf class
    >
    > $this->pages[$n]->SetMargins(20,47,20,20);
    > $this->pages[$n]->rodape_continuado('', 7.5, 240,
    117);
    > $this->pages[1]->SetMargins(20,47,20,20);
    > $this->pages[1]->rodape('', 7.5, 270, 117);
    >
    > I got on browser this
    >
    > Fatal error: Call to a member function SetMargins() on a
    non-object
    >
    > the goal is to make all my pages look equal, and then
    just change the first one
    >
    > how can I do this?
    >
    > many thanks in advance
    >
    >
    Kim
    http://www.geekministry.com

  • Set a container element inside class to exit a loop

    Hi,
    I want to set a container element inside a class to exit a loop.
    The element is marked as import/export parameter and the binding from the task to the container exists as well.
    The loop has a condition  &finish& = X but I cannot exit the loop. Looks like the value gets never updated in the container.
    When i am using a container operation to set the element its working but i want to do this out of my method in the class.
    Is it not possible to change a container element inside a loop without using a container operation?
    Thanks,
    Christoph

    Hi,
    Using the container operation is a good method to solve the problem. But if you intend to do that in the method coding itself then you will have to have it as the export parameter of the method. You can view all the import and export parameters of a method by going to the Business Object Builder (SWO1) and then choose the method and click on the "Parameters" Button. Once you are done with the interface of the method use that method in the workflow builder as a task and in the binding there are two rows. One for the import that occurs just below the container elements and the export parameters appear below the import in a separate window. Make sure you have the binding set there too as this is where you can transfer the container elements back to the workflow container from the task container and it should work. Maybe you are missing that in the binding.
    Hope it helps,
    Sudhi

  • How to use one variable for 2 datatype inside class

    Dear all
    i have create 2 class GDI and OGL need use use in M_VIEW as per condition
    in the class M_VIEW (example below)
    #define M_FLAG 1
    class GDI {public: int z;};
    class OGL{public: double z;};
    // in class M_VIEWi need to use GDI or OGL as per user condition
    class M_VIEW{
    public:
    #if (M_FLAG == 1)
    GID UseThis;
    #else
    OGL UseThis;
    #endif
    this is work but it always it take OGL. of if i change condition it take GDI only. but i need to use it runtime as per user choice.
    how to switch GDI to OGL, and OGL to GDI on runtime ;
    is that possible to change M_FLAG  value on run time or is there any other way to achieve it.
    i have try with polymorphism also. switch is ok but all function does not work with dll. when call function on mouse move or some other event it take base class virtual function. it doesn't goes to derived class function. don't know why?
    base class function like this and does not have any variable. all function are virtual.
    virtual void MoveLine(POINT pt1, POINT pt2){};
    virtual void DrawLine(POINT pt1, POINT pt2){};
    please help.
    Thanks in Advance.

    Well, #define, and #if are compile time only constructs.  Technically they are processed before you program is compiled (that is why they are called preprocessor directives).  If you need to support both flavors at runtime you will need a different
    approach.
    Inheritance/polymorphism could be a good approach here, but I don't really understand what you are trying to do well enough to say for sure.  Based on guesses about what you want, here are some thoughts.
    class GDI {public: int z;};
    class OGL{public: double z;};
    class M_VIEW_BASE {
    virtual void MoveLine(POINT pt1, POINT pt2) = 0;
    virtual void DrawLine(POINT pt1, POINT pt2) = 0;
    class M_VIEW_GDI {
    GDI UseThis;
    void MoveLine(POINT pt1, POINT pt2) override {}
    void DrawLine(POINT pt1, POINT pt2) override {}
    class M_VIEW_OGL {
    OGL UseThis;
    void MoveLine(POINT pt1, POINT pt2) override {}
    void DrawLine(POINT pt1, POINT pt2) override {}
    std::unique_ptr<M_VIEW_BASE> drawBase;
    enum DrawMode { DrawGdi, DrawOgl };
    extern "C" __declspec(dllexport) void Init(DrawMode whichMode) {
    if (drawMode == DragGdi) {
    drawBase.reset(new M_VIEW_GDI);
    } else if (drawMode == DrawOgl) {
    drawBase.reset(new M_VIEW_OGL);
    } else {
    throw std::runtime_exception("whoops");
    extern "C" __declspec(dllexport) void MoveLine(POINT pt1, POINT pt2) {
    drawBase->MoveLine(pt1, pt2);
    extern "C" __declspec(dllexport) void DrawLine(POINT pt1, POINT pt2) {
    drawBase->DrawLine(pt1, pt2);

  • How Do I Solve this IVI Class Conflict?

    I am trying to build a VI that uses the Refnum to Session VI included in the TestStand lib. The Refnum connector on the Refnum to Session VI seems to accept all types of IVI classes, but when i try to pass an IVI Refnum thru My own VI I can´t get it to accept all types of IVI classes. I have to select the specific class that the current instrument uses for the Refnum Control. Is there any solution to this problem? If I could open the Refnum to Session VI I might have a small clue how to do but now I am really lost in the dark.
    I attach a VI that shows how I would like it to work.
    All help is appreciated!
    Attachments:
    Using_the_Refnum_to_Session_VI.vi ‏18 KB

    Hello Jesper,
    as far as I know this is not possible with the current version of LabView 6.1.
    The workaround I use is to build a polymorphic VI. Although you have to spend some effort to build a separate VI for each type of Refnum but it pays back quite soon.
    The reason why you cannot edit "Refnum to Session" is because it's a Labview primitive and not a VI.
    This leads me to another question. Does anybody know on which LabView-Palette other than the TestStand-Palette I can find the "Refnum to Session" and "Session to Refnum" primitives?
    Regards
    Herbert
    Herbert Koltschik
    Sagem Communication Austria
    [email protected]

  • Why does this abstract class and method work without implement it?

    hi,
    I have seen many times that in some examples that there are objects made from abstract classes directly. However, in all books, manual and tutorials that I've read explain that we MUST implement those methods in a subclass.
    An example of what I'm saying is the example code here . In a few words that example makes Channels (java.nio.channel) and does operations with them. My problem is in the class to make this channels, because they used the ServerSockeChannel class and socket() method directly despite they are abstracts.
       // Create a new channel: if port == 0, FileChannel on /dev/tty, else
       // a SocketChannel from the first accept on the given port number
    private static ByteChannel newChannel (int netPort)
          throws Exception
          if (netPort == 0) {
             FileInputStream fis = new FileInputStream ("/dev/tty");
             return (fis.getChannel());
          } else {
    //CONFLICT LINES
             ServerSocketChannel ssc = ServerSocketChannel.open(); //<--I have never thought do that!! Anyway, how it is static method may work.
             ssc.socket().bind (new InetSocketAddress (netPort)); //<--but here, this method (socket) is abstract. WHY RETURN A SOCKET????????  this mehod should be empty by default.
             System.out.print ("Waiting for connection on port "
                + netPort + "...");
             System.out.flush();
             ByteChannel channel = ssc.accept();
             ssc.close();
             System.out.println ("Got it");
             return (channel);
       } I test this code and works fine. So why can it be??
    Also, I read that the abstract classes can't have static methods. Is it true???
    Please Help!!
    PS: i have seen this kind of code many times. So i feel that I don't understand how its really the abstract methods are made.
    PS2: I understand that obviously you don't do something like this: *"obj = new AbstractClass(); "*. I dont understand how it could be: ServerSocketChannel ssc = ServerSocketChannel.open(); and the compiler didn't warn.

    molavec wrote:
    ServerSocketChannel ssc = ServerSocketChannel.open(); //<--I have never thought do that!! Anyway, how it is static method may work.
    The static method creates an instance of a class which extends ServerSocketChannel, but is actually another non-abstract class.I thought that, but reading the documentation I saw that about open() method:
    Opens a server-socket channel.
    The new channel is created by invoking the openServerSocketChannel method of the system-wide default SelectorProvider object.
    The new channel's socket is initially unbound; it must be bound to a specific address via one of its socket's bind methods before connections can be accepted.
    ...and the problem is the same openServerSocketChannel is abstract, so i don't understand how it could return a ServerSocketChannel.There is a concrete implementation class that has implemented that method.
    I guess that really the open() method use a SelectorProvider's subclase but it doesn't appear in the doc.It doesn't need to. First, you don't care about those implementation details, and second, you know that if the class is abstract, it must use some concrete subclass.
    Ok, I speak Spanish by default (<-- this sounds like "I am a machine", ^_^' ). So, I didn't know how to say that the method would be {}. Is there a way to say that?? I recommendable for me to know, for the future questions o answers.Not sure what you're saying here. But the other respondent was trying to explain to you the difference between an abstract method and an empty method.
    // abstract method
    public abstract void foo();
    // empty method
    public void bar() {
    Which class does extend ServerSocketChannel? I can not see it.It may be a package-private class or a private nested class. There's no need to document that specific implementation, since you never need to use it directly.

  • Creating  a static method returning Logger Object inside class

    Hello,
    Instead of creating Logger Instance in every class , can i do like this way by creating a static method in some class returning a Logger object , and using that method for getting instance of Logger in another class through that method
    Regards
    Mayur Mitkari

    On a related note, if you want to make it simpler, never do this:
    if (a == true)Instead, just do if (a)It's pointless and cluttersome to use == or != with true or false.
    // wrong
    if (a == true)
    if (a != false)
    // right
    if (a)
    // wrong
    if (a == false)
    if (a != true)
    // right
    if (!a)Also, note that
    if (x) {
      return true;
    else {
      return false;
    }can be simplified to return x;If you do that and change your variable to something a bit more meaningful, like trueCount or numTrue or something, your code would be
    int trueCount = 0;
    if (a) trueCount++;
    if (b) trueCount++;
    if (c) trueCount++;
    return trueCount >= 2;which is about as simple and clear as it can get, IMHO. Using less code doesn't necessarily make the code simpler or clearer. The idea is that someone reading the code can easily understand what it does.
    And note that the above can be easily generalized to "Are there at least M true values in this array/list of N booleans?" and still be concise and clear.

Maybe you are looking for

  • Installing adobe photoshop cs6

    Im trying to install adobe photoshop cs6 and it says my serial number is invalid

  • Country of Delivering Plant is not showing in Sales Order Pricing Analysis

    Hello All, I have created a new condition table with the field Country of Delivering Plant (KOMK-WKCOU). But in the sales order pricing analysis this field is not fetching the country of the plant (it is showing the Yellow color exclamation icon). Th

  • MMPV - is Cost center assessment possible after closing period in MMPV?

    Hi, We are performing MMPV for April, which will close automatically postings for February. As far as I know MMPV opens and closes periods for MM postings only. Is that true? I would like to perform Cost center assesment and CC assessment to COPA for

  • Camera Raw Universal update not working

    Hey there .... heeeeelp .... I've just upgraded to a Mac Book Pro Core 2 Duo system, and it seems like the Camera Raw updater is not functioning on this system. I get no previews with my Canon 400D/XTi on import, which is what this update was suposse

  • Deleting RM's

    I've been doing some test streaming from my server into the native acrobat player and I'd like to delete (within acrobat ) some of the RM's in the Multimedia Operations list. Is there a way to do this ? Help appreciated.