Local class and switch statement -- compiler bug?

Does anybody know why the following does not compile with "LocalClass cannot be resolved to a type" error in the case 1: block
public class ProblemClass {
     public void localClassProblem() {
               class LocalClass {
                    void doNothing() {};          
               int i = 0; 
               switch (i) {                    
                    case 1: {
                         LocalClass instance1 = new LocalClass();  //ERROR: unresolved type
                                        break;
}while the following does (I only added case 2: where LocalClass type is not referenced within an embedded block)
public class ProblemClass {
     public void localClassProblem() {
               class LocalClass {
                    void doNothing() {};          
               int i = 0; 
               switch (i) {                    
                    case 1: {
                         LocalClass instance1 = new LocalClass();
                                        break;
                    case 2:
                         LocalClass instance2 = new LocalClass();
}Is it a compiler bug? Thanks for clarifying this.
--Michal                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

I'm using 1.5.0-b64
--Michal                                                                                                                                                                                                                                   

Similar Messages

  • What is meant by Local Class and how we can create local classes in abap?

    Hi Friends
    what is meant by Local Class and how we can create local classes in abap?
    Regards,
    Sree

    Hi
    Local classes are the classes which we declare and use using the SE38 ABAP editor
    Global classes are the classes which we find in SE24 and call the methods of them into our program.
    see the sample code
    REPORT zs_class.
    SELECTION SCREEN
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    PARAMETERS:p_var TYPE i,
    p_var1 TYPE i.
    SELECTION-SCREEN END OF BLOCK b1.
    CLASS d_class DEFINITION
    CLASS d_class DEFINITION.
    PUBLIC SECTION.
    METHODS:
    add,
    sub.
    PROTECTED SECTION.
    DATA : var2 TYPE i.
    ENDCLASS. "d_class DEFINITION
    CLASS d_class IMPLEMENTATION
    CLASS d_class IMPLEMENTATION.
    METHOD add.
    var2 = p_var + p_var1.
    WRITE:/ var2.
    ENDMETHOD. "add
    METHOD sub.
    var2 = p_var - p_var1.
    WRITE:/ var2.
    ENDMETHOD. "sub
    ENDCLASS. "d_class IMPLEMENTATION
    START-OF-SELECTION
    START-OF-SELECTION.
    DATA: obj TYPE REF TO d_class.
    CREATE OBJECT: obj .
    CALL METHOD: obj->add,
    Regards
    Anji

  • BUG - Switch statement & compiler

    I am overriding AccordionHeader. In the set Data method I
    have a switch statement. I dont think the location of the statement
    is relevant, but included for completeness. (MenuGroup is my own
    class and not relevant)
    If you have the following code Flex 3 \ FB 3 (both beta 3)
    override public function set data(value:Object):void
    var menuGroup:MenuGroup = value as MenuGroup;
    // examine the groupType to determine if we need \ want to
    change the style setting
    // on this particular header
    switch(menuGroup.groupType)
    super.data = value;
    The compiler will fail with an 'An internal build error has
    occurred' error.
    Put in a default case statement such as
    case default:
    break;
    and all is well.
    regards BOb

    Thanks for reporting. You can track the bug here
    https://bugs.adobe.com/jira/browse/ASC-3113
    Thanks,
    Gaurav Jain
    Flex SDK Team

  • Keyboard Input and switch statement error

    Hi,
    Below is a program to read an alphabet and check whether its a vowel/consonent using switch statement.
    Its always executin' the default stmt and not going into the case 1. This is because the ascii value of the character is being stored rather than the character.Could you please rectify this program?
    Thanks,
    vs
    import java.io.*;
    class vowel
    public static void main(String args[])throws Exception
    System.out.println("Enter a character:");
    char ch=(char)System.in.read();
    switch(ch)
    case 1: if(ch=='a')//||ch=='e'||ch=='i'||ch=='o'||ch=='u')
    System.out.println("The character is a vowel-a");
    break;
    default: System.out.println("The character is a consonent ! ");

         ch = Character.toLowerCase(ch);
         switch (ch) {
              case 'a' :
              case 'e' :
              case 'i' :
              case 'o' :
              case 'u' :
                   System.out.println("The character is a vowel: " + ch);
                   break;
              default :
                   System.out.println("The character is a consonent ! ");
         }

  • Local class and function group

    I want to write a local class in a function group, where is the best place I put the code? thanks!

    The best practice (according to a paper written by Horst Keller and Andreas Blumenthal - "An insider's guide...") is to put the DEFINITION in the TOP include and the IMPLEMENTATION part in a separate include such as LZ...C01.
    Get the paper here: https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c2992ca9-0e01-0010-adb1-b7629adb623c
    Regards
    Edited by: Alejandro Bindi on Apr 25, 2009 12:46 AM

  • Multiple rawValues and switch statements - can you do this?

    Hi, a simple question (i hope)
    first i have to use javascript for his one....
    Im just starting a form and it will have about a dozen dropdown lists (over about 15 pages), each with quite a few variables (i feel a headache coming on already...)
    and what i would like to be able to do is have text fields at the end of the form (hidden) and insert data into them depending on what combination of choices the user has made in some or all of the dropdown lists.
    I know how to get a standard switch statement to work fine but can you (and if so what is the syntax like) do this with multiple lists - and what event would be best to link it to - calculate perhaps?
    the switch would be using stored variables and user entered data to produce composite output to the text field (so case: listA.rawvalue = 1 and listB.rawvalue = nine, and listC.rawvalue = cat etc etc [then] this.rawvalue = v1.value + listB.rawvalue etc.....
    I'm sure you get the issue im struggling with  - I've tried it a few ways but my syntax must be off somewhere
    can anyone assist with the syntax for this kind of thing --or a sample would be fantastic.
    cheers

    Hey Legallogic!
    I'm not 100% certain I understand what you are struggling with but I'd be happy to help.  If you could provide an alternate explanation of your issue I'll take a look and help you solve it.  What I *think* you're asking about is in reference to the test case of a switch statement.  Typically a switch would be used to test the value of one particular variable, so:
    switch (varTest)
         case "A":
              //Do something here
              break;
         case "B":
              //Do something else here
              break;
         default:
              //Do something cool here instead
              break;
    Are you asking how to use a single switch to test the value of multiple variables (or fields)?  If so, my recommendation would be to simply use and if/else if/else block as you can craft your test cases however you'd like for those.
    Like I said, I may not have understood the issue here so feel free to shoot me an email and I'll take a peek!
    Josh Boyle
    Cardinal Solutions Group
    [email protected]

  • Problem with local class, static private attribute and public method

    Hello SDN,
    Consider the following situation:
    1) I have defined a LOCAL class airplane.
    2) This class has a private static attribute "type table of ref to" airplane (array of airplanes)
    3) A public method should return the private static table attribute
    Problems:
    a) The table cannot be given as an EXPORTING parameter in the method because TYPE TABLE OF... is not supported and I get syntax errors. I also cannot define a dictionary table type because it is a local class.
    b) The table cannot be given as a TABLES parameter in the method because TABLES is not supported in the OO context.
    c) The table cannot be given as an EXPORTING parameter in the method defined as LIKE myStaticAttribute because my method is PUBLIC and my attribute is PRIVATE. ABAP syntax requires that all PUBLIC statements are defined before PRIVATE ones, therefore it cannot find the attribute to reference to with LIKE.
    I see only 2 solutions:
    a) Never ever use local classes and always use global classes so that I might define a dictionary table type of my class which I can then use in my class.
    b) Make the attribute public, but this goes against OO principles, and isn't really an option.
    Am I missing anything here, or is this simply overlooked so far?

    Hello Niels
    Since your class is local and, thus, only know to the "surrounding" application is does not really make sense to make it public to any other application.
    However, if you require to store instances of your local classes in internal tables simply use the most generic reference type possible, i.e. <b>OBJECT</b>.
    The following sample report shows how to do that. Furthermore, I believe it also shows that there are <u><b>no </b></u>serious inconsistency in the ABAP language.
    *& Report  ZUS_SDN_LOCAL_CLASS
    REPORT  zus_sdn_local_class.
    " NOTE: SWF_UTL_OBJECT_TAB is a table type having reference type OBJECT
    *       CLASS lcl_airplane DEFINITION
    CLASS lcl_airplane DEFINITION.
      PUBLIC SECTION.
        DATA:    md_counter(3)             TYPE n.
        METHODS: constructor,
                 get_instances
                   RETURNING
                     value(rt_instances)   TYPE swf_utl_object_tab.
      PRIVATE SECTION.
        CLASS-DATA: mt_instances    TYPE swf_utl_object_tab.
    ENDCLASS.                    "lcl_airplane DEFINITION
    *       CLASS lcl_airplane IMPLEMENTATION
    CLASS lcl_airplane IMPLEMENTATION.
      METHOD constructor.
        APPEND me TO mt_instances.
        DESCRIBE TABLE mt_instances.
        md_counter = syst-tfill.
      ENDMETHOD.                    "constructor
      METHOD get_instances.
        rt_instances = mt_instances.
      ENDMETHOD.                    "get_instance
    ENDCLASS.                    "lcl_airplane IMPLEMENTATION
    DATA:
      gt_instances      TYPE swf_utl_object_tab,
      go_object         TYPE REF TO object,
      go_airplane       TYPE REF TO lcl_airplane.
    START-OF-SELECTION.
      " Create a few airplane instance
      DO 5 TIMES.
        CREATE OBJECT go_airplane.
      ENDDO.
      gt_instances = go_airplane->get_instances( ).
      CLEAR: go_airplane.
      LOOP AT gt_instances INTO go_object.
        go_airplane ?= go_object.
        WRITE: / 'Airplane =', go_airplane->md_counter.
      ENDLOOP.
    END-OF-SELECTION.
    Regards
      Uwe<u></u>

  • A function containing switch statement and foreach-object loop

    Hello Guys
    in my testdomain.lab, i have following five OUs in mt test AD structure:
    'OUusers', 'OUcomputers','OUservers','OUadministrators','OUhelpdesks'.
    i have created following five variables:
    $OUusers = 'ou=OUusers,dc=mytestdomain,dc=lab'
    $OUcomputers = 'ou=OUcomputers,dc=mytestdomain,dc=lab'and so on
    now i have created a function which gets this names as input &
    foreach-object creates the related OU.
    but the problem is sometimes when i run my function, maybe some of those five OUs
    currently exist in AD so this will cause a
    terminating error. 
    so i know i must use switch statement to define conditions like this:
    if $OUusers doesn't exist, execute this :  new-ADOrganizationalunit $OUusers
    if $OUcomputers doesn't exist, execute this :  new-ADOrganizationalunit $OUcomputers
    and so on...
    it's a long time which i am trying to create a
    function which contains such switch statement & properly forEach-object loop.
    i have studied switch and foreach-object loops , but this scenario is complicated for me & i was unable to get the correct code.
    Function createOUs {
    # combination of ForEach-Object and Switch statement here
    may someone give me the correct
    command please?
    thanks a lot

    Like this:
    $CompanyRoot=tha'ou=MyCompany, dc=mytestdomain,dc=lab'
    New-ADOrganizationalUnit -Name MyCompany -ErrorAction SilentlyContinue
    $ous='Users', 'Computers','Servers','Administrators','Helpdesk'
    foreach($ou in $ous){
    New-ADOrganizationalUnit -Name $ou -Path $companyroot -ErrorAction SilentlyContinue
    ¯\_(ツ)_/¯
    jrv, That can't be the solution because when you running a command which tries to creates an OU
    which already exist in AD, causes a
    terminating error which has two caveats:
    1- shows red error message on screen
    2- stops and doesn't continue to execute next lines of code
    Note that -ea silentlycontinue and -ea ignore have no effect on
    terminating errors and they cn't hide error messages, also script can't continue.
    i examined that.
    to get sure, run this function in your test AD & see the result:
    function createOUs {
    New-ADOrganizationalUnit -Name 'an-existing-ou' -Protected 0 -ea SilentlyContinue # you see that -ea silentlycontinue has no effect here
    New-ADOrganizationalUnit -Name '2ndOU' -Protected 0 -ea SilentlyContinue # you see that because the previous error has been a terminating error, command execution has been stopped and this 2nd OU hasn't been creatde
     another bad news is ( as i tested), if we query for an Organizational Unit which doesn't exist in AD , it generates a terminating error as well, so again here -ea has no effect.
    test this:
    PS C:\> Get-ADOrganizationalUnit -identity 'ou=nonesense,dc=yourDomain,dc=lab' -ea ignore
    error doesn't disapear ;-)

  • Continue in a switch statement

    What is the difference between using unlabelled continue and break in a switch statement?
    Looks like there is the same effect but I didn't found anything about using continue in switch in any documentation.
    Here's a typical explanation of using switch statement:
    "If the condition in a +switch statement+ matches a case constant, execution will run through all code in the +switch+ following the matching case statement until a +break statement+ or the end of the +switch statement+ is
    encountered. In other words, the matching case is just the entry point into the case block, but *unless there's a break statement*, the matching case is not the only case code that runs"
    Is it a good practise to use continue instead of break in such case?

    Books are right again :))
    Thanks everybody who wrote here.
    As I found out continue is only for use in the loop statements. I just use continue inside both for and switch statements and that's why I thought that it's appropriate to use it inside switch. No way!! In this way continue will affect only loop, not switch statement.
    For example:
    class BreakTest {
         public static void main(String[] args) {
              BreakTest br = new BreakTest();
              br.testContinue();
              br.testBreak();
         public void testContinue() {
              int[] int_arr = { 0, 0, 0, 0, 1, 0, 0 };
              int count_in_switch = 0;
              int count_in_for = 0;
              for (int a : int_arr) {
                   switch (a) {
                   case 0:
                        continue;
                   default:
                        count_in_switch++;
                   count_in_for++;
              System.out.println("count_in_switch=" + count_in_switch
                        + " count_in_for=" + count_in_for);
         public void testBreak() {
              int[] int_arr = { 0, 0, 0, 0, 1, 0, 0 };
              int count_in_switch = 0, count_in_for = 0;
              for (int a : int_arr) {
                   switch (a) {
                   case 0:
                        break;
                   default:
                        count_in_switch++;
                   count_in_for++;
              System.out.println("count_in_switch=" + count_in_switch
                        + " count_in_for=" + count_in_for);
    count_in_switch=1 count_in_for=*1*
    count_in_switch=1 count_in_for=*7*
    In case of using continue you won't get to count_in_for++; - you'll jump to the next iteration of for loop.
    In case of using break you'll go out of switch and go to next statement, that goes after switch block

  • I want the Definitaion fo  Class and its Components  in ABAP . With Example

    Gowri

    <b>Classes</b>
    Classes are templates for objects. Conversely, you can say that the type of
    an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes
    of objects are defined by the components of the class, which describe the
    state and behavior of objects.
    <b>
    Local and Global Classes</b>
    Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the
    ABAP Workbench. They are stored centrally in class pools in the class library
    in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.
    There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.
    The following sections describe how to define local classes and interfaces in an ABAP program. For information about how to define local classes and interfaces, refer to the  Class Builder section of the ABAP Workbench Tools documentation.
    <b>Defining Local Classes</b>
    Local classes consist of ABAP source code, enclosed in the ABAP statements CLASS ... ENDCLASS. A complete class definition consists of a declaration part and, if required, an implementation part. The declaration part of a class <class> is a statement block:
    CLASS <class> DEFINITION.
    ENDCLASS.
    It contains the declaration for all components (attributes, methods, events) of the class. When you define local classes, the declaration part belongs to the global program data. You should therefore place it at the beginning of the program.
    If you declare methods in the declaration part of a class, you must also write an implementation part for it. This consists of a further statement block:
    CLASS <class> IMPLEMENTATION.
    ENDCLASS.
    The implementation part of a class contains the implementation of all methods of the class. The implementation part of a local class is a processing block. Subsequent coding that is not itself part of a processing block is therefore not accessible.
    <b>Structure of a Class</b>
    <u>The following statements define the structure of a class:</u>
    A class contains components
    Each component is assigned to a visibility section
    Classes implement methods
    The following sections describe the structure of classes in more detail.
    <b>Class Components</b>
    The components of a class make up its contents. All components are declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility sections, which define the external interface of the class. All of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class.
    There are two kinds of components in a class - those that exist separately for each object in the class, and those that exist only once for the whole class, regardless of the number of instances. Instance-specific components are known as instance components. Components that are not instance-specific are called static components.
    In ABAP Objects, classes can define the following components. Since all components that you can declare in classes can also be declared in interfaces, the following descriptions apply equally to interfaces.
    <b>Attributes</b>
    Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.
    <b>Instance Attributes</b>
    The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.
    <b>Static Attributes</b>
    The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.
    All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.
    <b>Methods</b>
    Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.
    The definition and parameter interface of a method is similar to that of function modules. You define a method <met> in the definition part of a class and implement it in the implementation part using the following processing block:
    METHOD <meth>.
    ENDMETHOD.
    You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function modules). You call methods using the CALL METHOD statement.
    <b>Instance Methods</b>
    You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.
    <b>Static Methods</b>
    You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.
    <b>Special Methods</b>
    As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).
    <b>Events</b>
    Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method can be called by any number of users. When an event is triggered, any number of event handler methods can be called. The link between the trigger and the handler is not established until runtime. In a normal method call, the calling program determines the methods that it wants to call. These methods must exist. With events, the handler determines the events to which it wants to react. There does not have to be a handler method registered for every event.
    The events of a class can be triggered in the methods of the same class using the RAISE EVENT statement. You can declare a method of the same or a different class as an event handler method for the event <evt> of class <class> using the addition FOR EVENT <evt> OF <class>.
    Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.
    The link between trigger and handler is established dynamically in a program using the SET HANDLER statement. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.
    <b>Instance Events</b>
    You declare instance events using the EVENTS statement. An instance event can only be triggered in an instance method.
    <b>Static Events</b>
    You declare static events using the CLASS-EVENTS statement. All methods (instance and static methods) can trigger static events. Static events are the only type of event that can be triggered in a static method.
    <u>See also Triggering and Handling Events.</u>
    <b>Types</b>
    You can define your own ABAP data types within a class using the TYPES statement. Types are not instance-specific, and exist once only for all of the objects in a class.
    <b>Constants</b>
    Constants are special static attributes. You set their values when you declare them, and they can then no longer be changed. You declare them using the CONSTANTS statement. Constants are not instance-specific, and exist once only for all of the objects in a class.
    <b>Visibility Sections</b>
    You can divide the declaration part of a class into up to three visibility areas:
    CLASS <class> DEFINITION.
      PUBLIC SECTION.
      PROTECTED SECTION.
      PRIVATE SECTION.
    ENDCLASS.
    These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.
    <b>Public Section</b>
    All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.
    <b>
    Protected Section</b>
    All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.
    <b>Private Section</b>
    Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.
    <b>Encapsulation</b>
    The three visibility areas are the basis for one of the important features of object orientation - encapsulation. When you define a class, you should take great care in designing the public components, and try to declare as few public components as possible. The public components of global classes may not be changed once you have released the class.
    For example, public attributes are visible externally, and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, you cannot declare any public attributes. As well as defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.
    "Example  :
    CLASS C_COUNTER DEFINITION.
      PUBLIC SECTION.
        METHODS: SET_COUNTER IMPORTING VALUE(SET_VALUE) TYPE I,
                 INCREMENT_COUNTER,
                 GET_COUNTER EXPORTING VALUE(GET_VALUE) TYPE I.
      PRIVATE SECTION.
        DATA COUNT TYPE I.
    ENDCLASS.
    CLASS C_COUNTER IMPLEMENTATION.
      METHOD SET_COUNTER.
        COUNT = SET_VALUE.
      ENDMETHOD.
      METHOD INCREMENT_COUNTER.
        ADD 1 TO COUNT.
      ENDMETHOD.
      METHOD GET_COUNTER.
        GET_VALUE = COUNT.
      ENDMETHOD.
    ENDCLASS.
    The class C_COUNTER contains three public methods - SET_COUNTER, INCREMENT_COUNTER, and GET_COUNTER. Each of these works with the private integer field COUNT. Two of the methods have input and output parameters. These form the data interface of the class. The field COUNT is not outwardly visible.
    Reward   points  if it is usefull...
    Girish

  • Local class incompatible: different serialVersionUID

    Hi!
    I wrote an Object of type X to a file (in the server) and am sending the file to a client. This is done using:
    FileOutputStream fo = new FileOutputStream (filename);
    ObjectOutputStream so = new ObjectOutputStream (fo);
    so.writeObject(x); //x is of Object type X
    so.flush();
    so.close();
    fo.close();
    The file 'filename' is sent to the client and I read it as follows:
    FileInputStream in = new FileInputStream(filename);
    ObjectInputStream s = new ObjectInputStream(in);
    xobject = (X) x.readObject(); //xobject is of Object type X
    This is throwing an error as follows:
    java.util.Vector; local class incompatible:stream classdesc serialVersionUID = -2804478835259887871, local class serialVersionUID = -2767605614048989439
    Can anyone tell me what to do to be able to type cast the object and use it? I did go thro' some @serial documentation, but, couldn't understand it.
    Please help,
    Thanks,
    x86

    ...or, alternatively, maintain the X class in one package, the one where your server-side classes are compiled, say, and import it into the second, client side source code, which presumably lives in a separate package or this problem probably wouldn't have come up. The goal is never to have more than one copy of the compiled class file.
    You may have to modify your classpath.
    Hi!
    I wrote an Object of type X to a file (in theserver)
    and am sending the file to a client. This is done
    using:
    <snip>
    >
    This is throwing an error as follows:
    java.util.Vector; local class incompatible:stream
    classdesc serialVersionUID = -2804478835259887871,
    local class serialVersionUID = -2767605614048989439Hi
    try using one copy of the compiled class for the
    server
    and the client, I had this happen many times until I
    figured out
    the server compiled its version of the serialiable
    class and the client compiled its version of the
    serialiable class,
    then got class incompatable exceptions..among others
    easy way around this is to compile the code of botht
    he client and server, then copy the class code across
    to the client side
    Boris

  • What are exception class and persistant class?

    hi,
    what are exception class and persistant class?
    how are they different from the normal class?
    Regards,
    Anil

    Hii!
      Persistent Classes
    To use the Persistence Service for objects, the classes of these objects must be created as persistent classes in the Class Builder. The term persistent class does not imply that a class is persistent. (As a template for objects, every class is persistent). Rather, it means that the objects of that class and their state are managed by the Persistence Service. For example, the objects of these classes are instantiated in the ABAP program with a method of the Persistence Service, which ensures that the initialization is correct (not with the usual CREATE OBJECT statement). When the Class Builder creates a persistent class, it automatically generates an associated class, known as the class actor or class agent, whose methods manage the objects of persistent classes. As well as their identity, persistent classes can contain key attributes, which allow the Persistence Service to ensure that the content of each persistent object is unique.
      Check out this link
    http://www.sapnet.ru/abap_docu/ABENABAP_EXCEPTION_CLASSES.htm
    Regards
    Abhijeet

  • Compiler error when useing switch statements in an inner class

    I have defined several constants in a class and want to use this constans also in an inner class.
    All the constants are defined as private static final int.
    All works fine except when useing the switch statement in the inner class. I get the compiler error ""constant expression required". If I change the definition from private static final to protected static final it works, but why?
    What's the difference?
    Look at an example:
    public class Switchtest
       private static final int AA = 0;     
       protected static final int BB = 1;     
       private static int i = 0;
       public Switchtest()
          i = 0; // <- OK
          switch(i)
             case AA: break; //<- OK, funny no problem
             case BB: break; //<- OK
             default: break;
      private class InnerClass
          public InnerClass()
             i = 0; // <- OK: is accessible
             if (AA == i) // <- OK: AA is seen by the inner class; i  is also accessible
                i = AA + 1;
             switch(i)
                case AA: break; // <- STRANGE?! Fail: Constant expression required
                case BB: break; // <- OK
                default: break;
    }Thank's a lot for an explanation.

    Just a though:
    Maybe some subclass of Switchtest could decalare its own variable AA that is not final, but it can not declare its own BB because it is visible from the superclass. Therefore the compiler can not know for sure that AA is final.

  • Enum class not supported for switch() statement in 12.4 beta?

    Hi fellow 12.4 beta testers,
    It would appear "enum class" isn't supported for switch() statements in the 12.4 beta. This compiles fine under clang and g++. Will this be fixed for the final release? This currently causes compile errors for us, since __cplusplus >= 201103L evaluates to true, so our code uses "enum class" instead of plain "enum". It looks like the C++11 standard says it should be supported:
       Switching on enum class in C++ 0x - Stack Overflow
    Many thanks,
    Jonathan.
    $ cat test.cpp
    #include <iostream>
    enum class Ternary { KnownFalse = 0, KnownTrue = 1, Unknown = 2 };
    int main( void )
       Ternary foo;
       switch ( foo ) {
          case Ternary::KnownTrue:
          case Ternary::KnownFalse:
          case Ternary::Unknown:
             std::cout << "Success\n";
    $ clang++ -std=c++11 test.cpp
    $ g++ -std=c++11 test.cpp
    $ /opt/SolarisStudio12.4-beta_mar14-solaris-x86/bin/CC -std=c++11 test.cpp
    "test.cpp", line 8: Error: Cannot use Ternary to initialize integral type.
    "test.cpp", line 8: Error: Switch selection expression must be of an integral type.
    "test.cpp", line 9: Error: An integer constant expression is required for a case label.
    "test.cpp", line 10: Error: An integer constant expression is required for a case label.
    "test.cpp", line 11: Error: An integer constant expression is required for a case label.
    5 Error(s) detected.

    Thanks for reporting this problem! I have filed bug 18499900.
    BTW, according to the C++11 standard, the code is actually not valid. Section 6.4.2, switch statement, says an implicit conversion to an integral type is required, which is not the case for for a scoped enum (one using the "class enum" syntax). This limitation was raised in the C++ Committee as an issue to be fixed, and the C++14 standard makes the code valid.
    As a workaround, or to make the code conform to C++11, you can add casts to int for the enum variable and the enumerators.
    Message was edited by: Steve_Clamage

  • Switch statement and case variables

    Since constant variables do not have to be initialized when declared, they could be initialized later based on conditional logic and used to make the Switch statement more useful by using them as case labels. Well, sounds good in theory but I can't find anyway to make it work.
    I can't even get this to compile when the value of the case label is obvious at compile time :
    public class Switchtest
    public static void main(String[] args)
    int test = 0;
    final int x;
    x = 1;
    switch (test)
    case x: System.out.println("case x " );break;
    default: System.out.println("Default ");break;
    It gives an error about expecting x to be constant. I've tried static initializer blocks, etc. Is there anyway to have the case label variables initialized at runtime to make the Switch statement more useful?

    If jvm can use a hashtable for a switch statement. This hashtable is as constant as the compiled code, i.e., it can be defined at compile- time and it con not be modified runtime. Therefore a switch- case construction is faster than an else-if construction. But the strength of else- if is that it is more flexible. If you want to test on multiple variable values, you must use else-if
    class a
       public int method()
          int val = (int)(Math.random()*3);
          int x;
          if(val == 0)
             x = 1;
          else if(val == 1)
             x = 2;
          else
             x = 3;
          return x;
    class b
       public int method()
          int val = (int)(Math.random()*3);
          int x;
          switch (val)
             case 0:
                x = 1;
                break;
             case 1:
                x = 2;
                break;
             default:
                x = 3;
                break;
          return x;
    }b is bigger than a, but also faster. The technique used in a is more flexible, but b uses O(1) time where a uses O(n). (where n is the number of cases/else-ifs)

Maybe you are looking for