Static protected fields

Hi.
In inheritance, when a field is protected, I can access it in the subclass, but I can't access it from an instance of the parent class (the packages are different). Example:
package parent;
public class Parent {
    protected int j = 17;
package child;
class Child extends Parent {
    void m() {
        new Parent().j = 18; // compiler error
}However, when the field is static, referencing it from the Child class works fine:
package parent;
public class Parent {
    static protected int j = 17;
package child;
class Child extends Parent {
    void m() {
        new Parent().j = 18; // works fine
        Parent.j = 19; // so does this
}Could someone explain this to me? Is this a bug of the java implementation I am testing this on?

Could someone explain this to me? Is this a bug of the java implementation I am testing this on?It's not a bug. Aside from the static issue already addressed, protected members are accessible from implementation code. Example:
package a; // <------ Note this.
public class Foo {
    protected void fun() {}
package b;  // <---- And this.
import a.Foo;
class Main extends Foo {
    void test() {
        fun();      // this will work; part of implementation
        Main m = new Main();
        m.fun();    // this will work, too;
        Foo f = (Foo) m;
        f.fun();    // *this* won't work.
}~

Similar Messages

  • How to get protected fields

    Hello,
    I don't know how to get protected fields that a class inherits from its superclass through reflexion ... the getDeclaredFields method seems not working ...
    here is my test program:
    import java.io.File;
    import java.lang.reflect.Field;
    public class Test {
         public static void main(String[] args) {
              Field [] fieldList = SubClass.class.getDeclaredFields();
              for (Field field: fieldList) {
                   field.setAccessible(true);
                   System.out.println (field.getName());
         static class SuperClass {
              protected File file;
              public SuperClass () {
                   file = new File ("a.txt");
         static class SubClass {
              private File myfile;
              public SubClass () {
                   myfile = new File ("b.txt");
    The output is
    myfile
    This means, the getDeclaredField method of the SubClass returns only fields declared by this class, not protected fields declared by its superclass.
    Anyone has an idea to fix the problem, please help me. Thank you a lot
    }

    That's not a problem, the documentation specifically says that getDeclaredFields() only returns fields from this class. If you want fields from the superclass, why not just getSuperclass().getDeclaredFields()?

  • Static text field line height problem

    When an FLA that was created in OSX is edited on a PC the
    line heights in static text fields are lost. This was a problem in
    earlier versions of flash however it was generally fixable by
    republishing from the platform on which the text was originally
    set. As of CS3 the problem may have gotten worse:
    1. I developed a flash project in OSX CS3. It included many
    static text fields with varying individual line heights.
    2. I sent it to a colleague who was adding some tracking
    tags. He was working on a PC.
    3. He did his bit and sent it back.
    4. In the authoring environment the text looked fine. But
    after republishing, all the static text fields lost their line
    height settings - that is all the lines within any given text field
    inherited the line height of the first line within that text field.
    5. Only text fields that were edited by my colleague were
    affected by this problem. Text fields that weren't edited are fine.
    6. It seems that the only way to get past this problem is to
    actually delete these text fields and create new ones. This would
    take about a week. Republishing doesn't work.
    Any ideas?

    NP
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Kim" <[email protected]> wrote in message
    news:ern9ua$54m$[email protected]..
    >I was missing a div. Sorry for wasting your time. Thanks
    >
    > Murray *ACE* skrev:
    >> <p style="line-height:2.5;">about, <span
    class="xlarge"><a
    >> href="#article">articles</a></span>,
    blog, css, contact, Copenhagen,
    >> <span class="large"><a
    href="#article">download</a></span>, <span
    >> class="large"><a
    href="#logo">logo</a></span>, design, <span
    >> class="large"><a
    href="#draw">drawings</a></span>, family, freelance,
    >> football, graphics, javascript, monarchy, mysql,
    news, <span
    >> class="smallplus"><a
    href="#article">php</a></span>, portfolio, <span
    >> class="xlarge"><a
    href="#reboot">rebooted</a></span>, redesign,
    <span
    >> class="medium"><a
    href="#logo">republic</a></span>, seo, services,
    spam,
    >> universality, usability, <span
    class="smallplus"><a
    >> href="#work">websites</a></span>,
    webstandards, <span class="xlarge"><a
    >> href="#work">work</a></span>, xhtml,
    xml</p>
    >>
    >>
    >
    > --
    > Kim
    > ---------------------------
    >
    http://www.geekministry.com

  • MultiProvider report not functioning - overwriting protected field

    Hello,
    I have a multiprovider that combines data from the Sales Overview cube (0SD_C03) with a custom plan cube (data from COPA and SIS).  In writing queries off of the (active) multiprovider, short dumps occur except when only running against one infoprovider.  In other words, if the query is restricted to only show Sales data (0SD_C03), it works fine.  If the query is restricted to only show Plan data (custom plan cube), then it works fine.  However, the intersection of the two does not work - which is the entire functionality of the multiprovider (a join). 
    I've cut the query back to the very basics:  Fiscal Year and one Key Figure (that is present in both source infocubes).   Without specifying or splitting out the InfoProviders, it should combine the data (total the two), but instead creates a short dump.  Using a structure to split Actuals from Plan also results the short dump.  The only way to get the report to actually execute and return is to restrict it to just one InfoProvider.  I tried copying the MultiProvider and starting over, but that did not improve the situation.  The failure occurs after the variable screen has been filled in.  (Also tried w/out variables.)
    Using LISTCUBE, the data is found in a single execution (no filter applied to 0INFOPROV) and splits out to the two infoproviders w/ approp. fiscal year and Key Figure totals.  So there seems to be something at the reporting layer malfunctioning.
    Here's the ST22 short dump:
    Does anyone have any ideas?
    Runtime Error          MOVE_TO_LIT_NOTALLOWED_NODATA                                         
    Date and Time          07/17/2006 09:57:23                                                   
    ShrtText                                                                               
    Assignment error: Overwriting a protected field.                                        
    What happened?                                                                               
    Error in ABAP application program.                                                                               
    The current ABAP program "SAPLRSDRC" had to be terminated because one of the            
    statements could not be executed.                                                       
    This is probably due to an error in the ABAP program.
    rror analysis                                                                               
    The program tried to assign a new value to the field "<L_SX_OLAPQUERY>" even though it is protected against changes.                                                                               
    The following objects are protected:                                                       
       - Character or numeric literals                                                            
       - Constants (CONSTANTS)                                                                    
       - Parameters of the category IMPORTING REFERENCE for functions                             
         and methods                                                                               
    - Untyped field symbols to which a field has not yet been assigned                         
         using ASSIGN                                                                               
    - TABLES parameters if the corresponding actual parameter is protected                     
         against changes                                                                          
       - USING reference parameters and CHANGING parameters for FORMs if                          
         the actual parameter for this is protected against changes                               
       - Field symbols if the field assigned using ASSIGN or ASSIGNING                            
         is protected against changes                                                             
       - External write accesses to READ-ONLY attributes                                          
       - Key components of lines in internal tables of the type HASHED or                         
         SORTED TABLE                                                                               
    SORTED TABLE.    
    Message received in web report when failure occurs:
    Error when processing your request 
    Note
    The following error text was processed in the system BW1 : Assignment error: Overwriting a protected field.
    The error occurred on the application server bw_BW1_00 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Function: RSDRC_CUBE_DATA_GET_DISP of program SAPLRSDRC
    Function: RSDRC_MULTI_CUBE_DATA_GET_PARA of program SAPLRSDRC
    Function: RSDRC_MULTI_CUBE_DATA_GET of program SAPLRSDRC
    Form: DATA_GET of program SAPLRSDRC
    Function: RSDRC_CUBE_DATA_GET of program SAPLRSDRC
    Function: RSDRC_CUBE_DATA_GET_OLAP of program SAPLRSDRC
    Form: FILL_SP_1 of program SAPSRRK0
    Form: FILL_SP of program GP42GWU130B57UDR97PLRZOUC5Z
    Form: DATEN_LESEN of program SAPLRRK0
    Function: RRK_LIST_NOTIFY of program SAPLRRK0
    Thanks in advance!

    Hello
    Check OSS notes as below am not sure if it helps
    957439 - Query dumps with an error
    Below is for 3.5 and below ,just to let you know that there were similar problems in earlier version.
    941862 - *** Dump MOVE_TO_LIT_NOTALLOWED_NODATA with MultiProvider
    Chetan
    @CP..

  • Initializing a protected field in a subclass doesn't work

    Why doesn't this work? And if it shouldn't, how do I get around it?
    public abstract class Ship
         protected double rotationSpeed;
         protected aMethod()
              System.out.println(rotationSpeed);
    public abstract class Cruiser
         protected double rotationSpeed = 3;
    }I thought that when the method 'aMethod' it would print out '3' but it doesn't. I'm not sure why, I also tried this:
    public abstract class Cruiser
         public Cruiser()
              rotationSpeed = 3;
    But it didn't change it. How do I alter protected fields like this?

    happypigface wrote:
    Awesome, thanks, using super worked.You're welcome.
    Note that you don't need to use the 'super' keyword:
    class Cruiser extends Ship {
        public Cruiser() {
            rotationSpeed = 3; // this works too
    }but I find it clearer to use it.
    I didn't think it really mattered if I posted the code running it. I didn't really have one. The names of those fields and classes aren't real.
    ...IMO, it's best to post an SSCCE of the problem/question.

  • Password protect fields in interactive pdf

    Hi all,
    I have completed an interactive pdf online form and I want to make one of the sections (several fields) password protected. So two questions:
    How do you password protect fields?
    Do you have to apply password protection to each individual field or can you highlight a section (several fields) and password protect the whole section?
    Would really appreciate some help.
    Thanks so much. . .

    Many thanks George for your helpful advice. It is appreciated.
    Bridie Hanifee
    Pearson Trueman & Associates
    T:: +61 3 9864 7107
    F:: +61 3 9866 4811
    www.pearsontrueman.com<http://www.pearsontrueman.com>
    Please consider the environment before printing this email
    CAUTION - this message may contain privileged and confidential information intended only for the use of the addressee/s named above. If you are not the intended recipient of this message you are hereby notified that any use, dissemination, distribution, or reproduction of this message is prohibited. If you have received this message in error, please notify the sender immediately.

  • Static Interface Fields

    public interface interface {
         static public field = 1;
         public void methods();
    when is this correct to use in the OOP/Software Pattern paradigm?
    I thought interfaces were only there to define behaviors (i.e. methods)
    What are static fields doing here?
    Why are static methods not allowed in interfaces while static fields are?
    Thanks

    public interface interface {
         static public field = 1;
         public void methods();
    }Indded it should be public static final (i.e., constants). The compiler supports not specifying final, and adds it automatically, but one should make that explicit.
    when is this correct to use in the OOP/Software
    Pattern paradigm?Unlike the previous posters, I don't find that bad against OO principle.
    If a constant is logically related to the capabilities defined by an interface, it's not a bad thing in itself to declare the constants in the interface's namespace.
    public interface HairDressable {
      public static final int BLONDE = 0;
      public static final int RED = 2;
      public static final int BLACK = 3;
      public void haveHairCut();
      public void haveColorChanged(int newColor);
      public int getHairColor();
    }All classes implementing the interface automaticaly see the constant, and can refer to it without prefixing by the interface name. public class PomPomGirl implements HairDressable {
      public void haveColorChanged(int newColor) {
        if (this.favoriteTeam.getName().equals("Red Socks") && (newColor!=RED)) {...}
    }Any class not implementing the interface can also refer to the constant, by prefixing with the interface's name, as in public class RedTeamFanClub {
    public void makeUp(PomPomGirl pomPomGirl) {
        pomPomGirl.haveColorChanged(HairDressable.RED);
    } What IS bad is to have a class implement the interface only for the sake of referring to the variable without prefixing, like public class HairDresser implements HairDressable {
      public void handleFancyLady(Bimbo bimbo) {
        bimbo.changeColor(RED);
      // Dummy implementation of method that should belong here
      public void haveHairCut() {}
      public void haveColorChanged(int  c) {}
      public int getHairColor() {return BLACK;}
    I thought interfaces were only there to define
    behaviors (i.e. methods) I would say "to advertise capabilities".
    Here both changing the color and getting the current color are capabilities that involve a notion of color that is common to all HairDressable implementing classes. I deem defining this notion in the interface itself makes sense.
    (OK, defining this notion as a bunch of int constants is not very well engineered, but let's keep the discussion focused).
    Now there's the pragmatic approach too : if you define constants in your interface, you run the risk that a bad programmers will someday implement the interface only to lazily refer to the constant.
    But you run that risk with abstract classes too - yes, I've seen that!
    Why are static methods not allowed in interfaces while
    static fields are?Only static final fields, which makes a difference.
    Static methods don't advertise the capabilites of an object. And they can't be overridden.
    Neither does a constant, in itself, but there's a point in defining the constant in the scope where it makes the most logical sense.
    For completeness, note there's an RFE on the BugParade to add statis methods to interfaces (http://developer.java.sun.com/developer/bugParade/bugs/4093687.html).
    As I understand it, and although I don't support it, I think there's a point in defining a static method and its implementation in an interface, so as to, in the same vein as for the constants, put in the interface's scope a method whose implementation logically has a meaning for all implementing classes of the interface
    (I'd say such methods are rare enough not to deserve a language change).
    But it seems ugly (and fortunately impossible at that point) to add the notion of "abstract static methods" that an interface could declare and all implementing class would have to implement.

  • How to use reflection to get base classes protected field

    I have one base Base classes which have protected fields and public get method to get the field.
    class Base
    protected int proField;
    public int getProField(){return proField;}
    Class Derive extends base class Base
    class Derive extends Base implements OtherInterface
    public void funtion(){};
    Now I have an instance of Derive, how can I use reflection to get the protected field inherited from Base. It seems Java Reflection only give runtime accessibility to public field and decleared field, protected-inherited field is excluded.
    Thanks
    Lei

    as the last poster said, traverse up the class hierarchy.
    ex:
    private void doSumfinToField(String fieldName throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException {
    Class clazz = getClass();
    Field field = findFieldInClass(clazz, fieldName);
    //field.doSumfin;
    private Field findFieldInClass(Class clazz, String fieldName) throws NoSuchFieldException {
    try { // to find the field in this class    
    return clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
    // if we don't have a superclass, continue
    if (clazz.getSuperclass().equals(Object.class)) {
    throw e;
    // check in the superclass
    return findFieldInClass(clazz.getSuperclass(), fieldName);
    }

  • Font not embedded in static text fields...

    I think the title says it all. I'm building website and I've come half way now just to notice that my clients cant see my font that supposed to be there. What I've learned so far is that in static text fields, flash should embed it itself since I can't reference to it + embedFonts property not working, how can I fix this problem? Anyone had anything similar? What are common mistakes? I'm pretty new at all of this...
    Thanks

    thx for answers...
    Font Name                 Bytes        Characters   
    Klavika-Regular                4555     ,-./0123789:@BCKNPVZabdefghijklmnoprstuvy
    NeoTech                        6738     ,.ACDEFIKLMNOPRSTUVZabcdefghijlmnopqrstuv
    there they are...
    FLASH CS4
    font: NeoTech
    url: http://www.centar-bundek.hr/test/

  • Display text w/i Static Text Field

    Running SJSC2.1 on XP
    How can I get the text within a static text field to display on multiple lines.
    It works within a text area field - using "\n" but not a static text field. The text is fed from a database (Derby/Oracle)??
    Thanks...

    I have inserted: escape="false" as here:
    <ui:tableColumn binding="#{Page1.tableColumn3}" headerText="Info" id="tableColumn3">
    <ui:staticText binding="#{Page1.staticText5}" escape="false" id="staticText5" text="#{currentRow.value['CONTACT.CINFO']}"/>
    There is no option in properties for table cells (static text)
    Still the text is one long string..
    However, looking at the source code after deployment shows newlines where they should be. Go Figure!
    Could certainly use some help here..
    Thanks

  • Assignment error: Overwriting a protected field.

    Hi All,
    When I try to post some data from XI through an inbound proxy to R/3, the message get stuck in the R/3 inbound queue because of the SysFail with the error "Assignment error: Overwriting a protected field."
    If I goto SPROXY and debug the interface with the same message payload from the monitor, the execution runs through without any errors.
    If anyone has come across this kind of situation, please throw some light.
    Thanks
    AJ.

    Hi,
    When ur sending data from Source system its giving error,in SPROXY if u post data its not giving any error.R u using any date formats in source side,this will happen when ur data is worng and XI is not transforming the data into ABAP format.
    I to got same error when i have date format at source side.
    'First Check what are the transformation ur using in XI mapping.all are working fine or not.
    After that Take the payload of receiver side in SXMB_MONi and using it execute the proxy then u can find the error.
    Regards,
    Phani
    Reward points if Helpful

  • Cannot override protected fields

    I know this is not possible, but my question is why did they design it
    that way:
    public class ParentForm {
    protected String name = "ParentForm";
    protected String getName(){return name;}
    public class ChildForm extends ParentForm{
    protected String name = "ChildForm"; //I am trying to override
    the field value but reuse the method from parent.
    public class Test {
    public static void main(String[] args) {
    System.out.println((new ParentForm()).getName());
    System.out.println((new ChildForm()).getName());
    Output:
    ParentForm
    ParentForm
    I wanted to see "ChildForm" in the second line. Why do I have to
    duplicate (literally cut and paste) the getName() method in the child
    to achieve it ?
    Can someone explain the concept I am missing ?

    Wouldn't it be good have the privilege ofsaying,
    "I
    am extending your class wherein I want to
    inherit
    everything from you except override the value ofthis
    one field" ? I've never encountered a situation where thatwould
    be useful.Well, it will surely save a lot of unnecessary coding
    writing dummy methods.I've never had to write dummy methods.
    Like I said, I think the real problem is in your design.

  • Protect field bsec-bankn (one-time vendor) within transaction fb02

    The user who can do " F110 automatic payment transaction" should not be able to change the bank number (bsec-bankn) of an one-time vendor for security reasons. A tried to customize the field groups and put them in the authorization object "F_lfa1_aen" but ended with a problem. It is not possible to add field bsec-bankn into a field group.
    Is it possible to protect this field from being changed for certain users (not all)?

    Hi Donald, as you can see in my container session I do specify:
    <uses-external-connection-pool>true</uses-external-connection-pool>
    I think the problem I have is that cannot co-exists in the same sessions.xml file two sessions one container and one non-container.
    When we ran the non-container server and when sessions.xml has the two sessions inside TopLink it will try, as part of parsing the sessions.xml (and before I really login), to instantiate the External Controller class even so I am not login for that session.
    It would be nice that the TopLink parser does not instantiate the classes at the time of parsing but leave the instantiation for the time of logging in the specific session. For me sessions.xml is a configuration file and it should not force to load and instantiate classes which I do not intend to use at some given time.
    Thank you, Narcisa

  • Modify default value for static parameter field programmatically

    Hi,
    I have my Crystal Reports stored in a BO Enterprise system. I have written a java programm that scans the repository, loads the CR reports one by one into a ReportClientDocument, modifies the data source and then stores the updated report back to repository (it overwrites the existing objects).
    I was even able to modify the default values for the parameters, which are used for scheduling of each report.
    But what I am trying to do know is to overwrite the default value used when invoking the report interactively. This should be the value found under the Default Value field, when the Properties window of the parameter is opened in the CR designer.
    This is what I have tried so far:
    Option 1: First I tried to set the default values using com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.getDataDefinition().getParameterFieldController().getField(...).getDefaultValues() . The only thing I have managed to do using this approach is to modify the static LOVs that are associated to static parameters. The actual selected value (shown under Default Value in the Properties window for the given parameter field) remained unchanged, when invoking the report in the InfoView or opening it in the CR designer.
    Option 2: I have used com.crystaldecisions.sdk.plugin.desktop.report.IReport.getReportParameters().get(ik).getDefaultValues() to change the default values. I was able to see my changes in the BO repository (using a query on CI_INFOOBJECTS), still the changes did not really have an impact to what is displayed as default value when invoking the report in the InfoView.
    Any help will be appreciated.
    It would be great to know if someone of you has already implemented successfully such a use-case.
    Regards,
    Stratos
    Edited by: Efstratios Karaivazoglou on Dec 9, 2009 8:52 AM
    Edited by: Efstratios Karaivazoglou on Dec 15, 2009 11:33 PM

    Hi,
    For Crystal Design related queries, close this thread and start the thread in the [SAP Crystal Reports Design forums|http://forums.sdn.sap.com/forum.jspa?forumID=300&start=0]
    - Bhushan

  • Forcing implementation of an inherited static method/field?

    Suppose I have some classes - BlueAction, RedAction etc - extending an abstract base class called BaseAction. I put an abstract method called getColour() in BaseAction, and implement it in all the classes that extend it, so BlueAction returns blue, and so on. Fine.
    I now want to use a class loader to get their colour, but crucially, I don't want to instantiate them, so instance methods are out.
    If you could declare abstract static methods, I'd do that, and be assured that every implementation of BaseAction contained the necessary info. Obviously you can't do this.
    I think I could just put a static method or field in each one, and access that via something like Class.getField("COLOUR")but then there's nothing to force me to put that code into each implementation.
    Is there anything clever I can do?
    Cheers,
    Rob
    Edited by: arewenotmen on Jun 20, 2008 3:51 AM

    baftos wrote:
    I guess it should be possible. Me, I did play with runtime annotations, but I am scared like hell
    of compile time annotation. My reasons, but maybe I am wrong:All good reasons.
    - Modify the build process to use APT instead of javacYou could use in -nocompile mode and add a task to the build script.
    - Writing annotation processors, big overheadI had a play, was not too hard to get started with, but then it started to get wierd and data I expected was not being returned.
    - Using com.sun classes in the processors instead of java/javax classes (subject to change?)Java 6 has the javax.annotations package (also works with javac rather than a different tool), but this seams less powerful than apt.
    A fair few things now mean the "don't touch the com.sun package" rule is being eroded. The httpd is in it as well.

Maybe you are looking for

  • Will the new lightning to 30-pin adapter support.... ?

    Will the new lightning to 30-pin adapter support a cord at which the 30 pin goes and splits into a RCA cable for audio output and USB for charging, this is what is used in my car currently to feed my former iphone 4 into the cars stereo while also ch

  • Yet again another problem!

    First 'disk cannot be read' That causes me to unplug the ipod, then plug it back in. I've tried, USB hubs, flipping every usb i have in my computer, restoring the ipod, re-installing itunes... I was about 450 songs in with all their artworks all nice

  • My mac is not listed under iCloud devices

    hi everone I configured "find my mac" and my macbook pro has recovery partition too, but I cant see my macbook pro in icloud. what am I missing ?? Thank you 

  • C libraries for Oracle 8i

    I am trying to find the c libraries for Oracle, and any documentation out there. Anyone point me at the FM?

  • Monitor server availability

    I would like to monitor availability of Windows server (VM/Hosts). Could someone please advice me the ways to do that. e.g. 99% for last one month TIA