Will 1.5 compiler tag default constructor as synthetic?

Hi,
This is a question about the synthetic attribute for the default constructor. This attribute has been added at the moment the inner classes have been introduced in the language. I think its purpose is to distinguish methods added by the compiler (like the access methods) to handle the inner classes.
Synthetic basically means something that has been added by the compiler and that has no corresponding source code.
Following this, the default constructor (added when the class has no constructor) should also be tagged with a synthetic attribute, shouldn't it?
Javac 1.4.2 doesn't add this attribute for the default constructor and I was wondering if the version 1.5 would do it.
Thanks,
Olivier

As far as I tested the jdk 1.5 compiler, I found that
it already tags default constructors with isSynthetic
attribute. Default constructors are compiler generated
and I am not sure how it affects the api, if they are
tagged isSynthetic.No, the 1.50 beta 31 compiler does not tag default constructors with Synthetic attributes.

Similar Messages

  • Selective member import/export using dllexport and default constructor

    We can only export some methods in the class(https://msdn.microsoft.com/es-es/library/8d7d1303-b9e9-47ca-96cc-67bf444a08a9%28v=vs.100%29)
    What if we export only some methods in the class and not exported the default constructor(Will it get generated by the compiler in external app which use this dll?).The class may have some private data member as well which are not exposed in the published
    header file(Which we distribute with DLL).
    How the memory gets allocated to those private data members which are not exposed as the default constructor is not exported? 
    Niranjan

    We can only export some methods in the class(https://msdn.microsoft.com/es-es/library/8d7d1303-b9e9-47ca-96cc-67bf444a08a9%28v=vs.100%29)
    What if we export only some methods in the class and not exported the default constructor(Will it get generated by the compiler in external app which use this dll?).The class may have some private data member as well which are not exposed in the published
    header file(Which we distribute with DLL).
    How the memory gets allocated to those private data members which are not exposed as the default constructor is not exported? 
    Niranjan

  • Super class default constructor

    Hello,
    I want to clear some confusion. I am studying for the exam. In this particular book an example shows that
    Super class has 2 constructor
    public abc() and public abc(int n)
    Sub class has 2 constructor
    public xyz() and public xyz(int n)
    now when an instance is created for the subclass
    xyz t = new xyz(1)
    It will invoke the super class no argument constructor eventhough a default constructor exist in subclass?
    Regards,
    adil

    Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Default Constructor

    referring to - http://www.javapractices.com/Topic40.cjp
    If the programmer does not provide a constructor for a class, then the system will always provide a default, no-argument constructor. To disable this default constructor, simply add a private constructor to the class. This private constructor may be empty.
    then, i tried this
    class A
         int x;
         A(int x)
              this.x = x;
    class Demo
         public static void main(String args[])
              A a = new A();                            // error
              System.out.println(a.x);
    }so, if i provide a one-argument constructor, the zero argument constructor aint no longer provided by the compiler automatically?

    Well, hey, since it's a g@ngbang...
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • No appropriate default constructor c++

    Hi, have been trying to read up on it but I need some help to understand it, here's my code. What should I do to make it work and how should I try to think about it in the future?
    cheers
    Law.h
    #include <iostream>
    #include <string>
    using namespace std;
    class Law
    private:
    int k;
    int x;
    int F;
    int m;
    const int g;
    void init();
    public:
    void Introduce();
    int getMass();
    int getLenght();
    Law.ccp
    #include "Law.h"
    int Law::getMass()
    return m;
    int Law::getLenght()
    return x;
    void Law::Introduce()
    cout << "\nWelcome to a very simplified Hooke's Law Calculator" << endl;
    cout << "\nplease type in your mass: ";
    main.ccp
    #include <iostream>
    #include <string>
    #include "Law.h"
    using namespace std;
    int main()
    Law hLaw;
    hLaw.Introduce();
    system("pause");
    return 0;

    On 1/11/2015 8:50 AM, RonnerBBQ wrote:
    class Law
    private:
    const int g;
    Law hLaw;
    The variable hLaw needs to be initialized - with a default constructor in this case. Class  Law doesn't have any user-defined constructors. Normally, a compiler would implicitly define a default constructor, equivalent to Law::Law() {} . But in
    this case, it can't - Law has a const data member, which must be initialized in constructor (it being const, there won't be any other chance), and the compiler doesn't know what value to initialize it to.
    You can 1) explicitly define a default constructor, and initialize g there, or 2) drop "const" from g (or drop g entirely, seeing as you aren't using it), or 3) give g an initializer, as in "const int g = 42;"
    Igor Tandetnik

  • Always create any Object even without default constructor?

    hi!
    i'm wondering if there's an easy way to construct an object of a given class?
    let's assume i've got a class
    class MyClass
         public MyClass( OtherClass c)
    }now when i get the constructors for its Class-object with
    clazz.getDeclaredConstructor()
    it will return null;
    ok now i know ther's no default/empty constructor.
    does it make sense to then search for the next constructor with n parameters?
    and then invoke it with nonsense values?
    what happens if the parameter classes also have no default constructor to create parameter objects? like this:
    class OtherClass
         public OtherClass ( MyClass c)
    }now there's a loop between the two constructors and i can't create empty parameter values to invoke any of them!
    i wonder how the serialization engine works then?
    or did i miss something trivial (it's really late here ;) )

    What's the problem? To create a MyClass object, you
    don't need any OtherClass objects. You just do the
    equivalent ofnew MyClass(null)in your
    reflective code.
    slap forehead with toilet
    thanks for the tip.
    as i said there was something absolutely easy, it's tough not seeing the forest for the trees ;/
    But I agree with jschell, if your requirements are to
    create objects of arbitrary classes and call
    arbitrary methods with arbitrary parameter lists,
    then whoever did your design didn't think for long
    enough.WELL. you're absolutely right. but when it's time to process ANY given object there's no reliability on whatever design was chosen. or, would you insist the developer had to provide standatized formats when you write a debugger? no it has to work with any. so must i!

  • Anonymous classes and non-default constructors

    I've got a class with only one constructor and that takes an argument. In another class, I want to have an anonymous class that extends this class with something like:
    new MyClassWithoutDefaultConstructor(myConstuctorArg) {...}
    However, I get a "The constructor MyClassWithoutDefaultConstructor() is undefined".
    As a workaround I can create a local class (not anonymous) that extends MyClassWithoutDefaultConstructor and then includes a default constructor which passes my arg to the super constructor. But this is rather messy.
    Am I missing something?

    The following works fine for me (prints 5):
    public abstract class Test
        private final int parameter;
        public Test(int parameter)
            this.parameter=parameter;
        public int getParameter()
            return parameter;
        public abstract int getSomething();
        public static void main(String[] args)
            Test test=new Test(3)
                public int getSomething()
                    return getParameter()+2;
            System.out.println(test.getSomething());
    }You say your anonymous class is in a different class to the one it extends - what is the access modifier on the constuctor you are calling in the base class? Is the constructor visible from the class containing the anonymous class? Can you post a concise example that produces the compiler error that you are getting?

  • How can i set a breakpoint on a default constructor

    I'd like to catch all instances where a specific class is constructed but only the default constructor exists and it is implicitly defined.  How can I break in the default constructor?  
    thanks,

    There is no code where you want a breakpoint, so I'm not sure what instruction you'd like the debugger to break your program at.  ???
    Since your goal is only to "catch" all instances where a specific class is constructed I think the only thing is to modify your code to do so.  I can't think of an approach that doesn't require a code modification and recompile.  Especially
    since it's not clear where such classes were inlined in already compiled code.  And because of that alone, I'm
    fairly certain you have to instrument your code (modify your code by inserting something special) to catch it.  
    So can you modify the class you want to catch?  Just add a default constructor and set your breakpoint in there.
    Alternatively if you really want to try to do what you are doing, you can step into any code that creates an instance of your class in disassembly and set a breakpoint in the disassembled code for the constructor (assuming you can locate it, and it even
    exists), then rerun your program.

  • How to implement public default constructor for type

    i copy the servicestack dll from old project for redis 2.6, without using nuget
    i add new() but can not compile
    without new(), it has error , requires public default constructor
    type LogicDataBase =
    { mutable BitKeyFunctionValue1 : Dictionary<String, Dictionary<expr, expr>>;
    mutable PathList1 : Dictionary<expr list, expr list>
    mutable AllImplicationKeyList1 : expr list
    new() = LogicDataBase(BitKeyFunctionValue1, PathList1, AllImplicationKeyList1)
    let redisClient1 = new RedisClient("localhost")
    let d1 = {
    BitKeyFunctionValue1 = BitKeyFunctionValue
    AllImplicationKeyList1 = AllImplicationKeyList
    PathList1 = PathList
    redisClient1.Store<LogicDataBase>(d1)
    redisClient1.Save()
    let redisClient2 = redisClient1.As<LogicDataBase>()
    let rediskeys : List<String> = redisClient2.GetAllKeys()
    for kk3 in rediskeys do
    let d2 : LogicDataBase = redisClient2.[kk3]
    BitKeyFunctionValue <- d2.BitKeyFunctionValue1
    AllImplicationKeyList <- d2.AllImplicationKeyList1
    PathList <- d2.PathList1
    let debugBitKeyFunctionValue2 = BitKeyFunctionValue
    let debugAllImplicationKeyList2 = AllImplicationKeyList
    let debugPathList2 = PathList
    computing nightmare

    is there an example about this for this case?
    i see that type is also a class, where is wrong?
    type LogicDataBase =
    { mutable BitKeyFunctionValue1 : Dictionary<String, Dictionary<expr, expr>>;
    mutable PathList1 : Dictionary<expr list, expr list>
    mutable AllImplicationKeyList1 : expr list
    new() = LogicDataBase(BitKeyFunctionValue1, PathList1, AllImplicationKeyList1)
    computing nightmare

  • Newbie question about default Constructors

    I have this simple class with a constructor:
    ============================================================
    public class ScopeTest {
    public static void main(String[] args) { ScopeTest tst = new ScopeTest(); }
    public ScopeTest(String a) { System.out.println("ScopeTest(String a) : " + a); }
    ============================================================
    This class generates these errors when compiling:
    ScopeTest.java:3: cannot find symbol
    symbol : constructor ScopeTest()
    location: class ScopeTest
    public static void main(String[] args) {ScopeTest tst = new ScopeTest();}
    ^
    All the books and tutorials I read say that the compiler invokes the constructor of the super class (Object in this case)
    if it can't find one with the right signature in the class. Yet if I comment out this class's constructor it compiles and works.
    Can anyone explain???

    so u hv to put a default constructor...
    public class ScopeTest {
    public static void main(String[] args) { ScopeTest tst = new ScopeTest(); }
    public ScopeTest(String a) { System.out.println("ScopeTest(String a) : " + a); }
    public ScopeTest() { System.out.println("Default Constructor"); }
    }

  • ConstructorDoc always shows a non default constructor

    If the source file has no explicite constructor, the ConstructorDocs of ClassDoc always hold a non default constructor as it seems. If there is an explicite coded constructor, the position of the constructor points to the right position in the file. If there is no constructor in the source, it points to the class declaration. Is this a javadoc bug or has anybody seen this problem before?

    I believe, all you need is to check the method: MemberDoc.isSynthetic() It is inherited by ConstructorDoc from the com.sun.javadoc.MemberDoc interface.
    This method is provided specifically to know (and filter out when needed) if the member is implicitly synthesized by the compiler.
    Regards,
    Leonid Rudy
    http://www.docflex.com

  • Default constructor and inheritance

    Hi all.
    I have a class that represents a contact. A contact object is valid if both name and number have been specified. Otherwise I want to be notified via a dedicated exception.
    This is the code:
    public class Contact
        private String contact[] = new String[2];
        public Contact(String name, String number) throws InvalidContactException
            setName(name); // a method to set contact[0]
            setNumber(number); // a method to set contact[1]
            if (isValid()) // a method to check if both name and number have been specified.
                throw new InvalidContactException(); // this class inherits from Exception.
            // other class methods.
    }This is my questions:
    As the the constructor public Contact() wouldn't create a valid object, I have omitted it. Is it a good thing? I know that if some new class will extend Contact by inheritance, its default constructor will call the default constructor of super class (Contact), which does not provide one. This probably will cause some kind of error.
    Then I thought to provide a such constructor:
    public Contact() throws InvalidContactException()
    this("", ""); // It asks for a not valid contact.
    }I don't feel it's a clean solution, am I following an acceptable way?
    Thanks for your attention

    I'm not sure what your point is, especially thepart
    about "since the JMM is broken, the order cannotbe
    guaranteed." Can you be more specific? The JLS is
    quite specific on what happens and in what orderwhen
    an object is created, including when an exceptionis
    thrown.
    [url
    http://java.sun.com/docs/books/jls/third_edition/html/
    execution.html#12.5]JLS 12.5 Creation of New
    Class
    Instances
    What downside are you claiming to throwing an
    exception from a c'tor?IMHO The JLS does specify the steps but doesnot
    mention the order. Please correct me if it specifies
    the order as well.
    Read that section. The order is the order it states there.
    >
    If an exception is thrown in a constructor would an
    object be created or not?
    A a = new A();
    Depends what you mean by "object created." The memory is allocated. Which of the rest of the steps have been run (instance initializers, ancestor c'tors, this c'tor) depend on where the exception was thrown. Regardless, though, you won't get back a value in the variable a.
    now the constructor A() throwns and exception. My
    question is would a be null in that case or not?a will have whatever value it had before that method, if any. But it doesn't matter, because, since an exception has been thrown, the steps after that statement are not executed.
    Specially considering as I mentioned the order is not
    guaranteed in my previous post and JMM is broken.You have yet to provide support or clarification for this, or what it means in this context.
    Considering a might or might not be null ,There is no "might or might not." See above.
    what
    would be the benefit of such an exception.
    Following the broken DCL semantics and I am sure
    you must have gone through articleDCL is a completely different issue.

  • Require default constructor

    Although I doubt there is, I would like to know if there is a way to require subclasses to implement the default constructor. I am retrieving String class names from a data file and creating objects with the combination of Class.forName(...) and newInstance() (also from Class class). I just wanted to create them without having to deal with various combinations of constructors.

    CharanZ wrote:
    Java Creates a default constructor for every class you create, Unless you override it.Except that a) C'tors are not inherited and thus cannot be overridden, and b) If you explicitly define any c'tor, then the compiler no longer provides the default.
    So no need to worry about it.Except that there's no way to do what the OP asks, except, as already pointed out, by documentation and trusting the subclass author to follow it.

  • Default Constructor Help?

    class A {
    public A() {
    public A(int) {
    //--main method--
    }This is an assignment that I'm having some trouble with So let's say I have class A and the default constructor, as well as a constructor that takes an int. The default A constructor is supposed to have an object created by a call to the default constructor of objects, java.lang.Object. However, if I try to refer to the default Object() constructor by using super();, it creates a NullPointerException error (obviously). So is there some sort of default object or something that I'm supposed to use?
    Thanks for all the help :)

    I mean it generates the error during runtime; i can compile it okay.Sorry, I missed that you said it was a NullPointerException.
    For example, it seems to generate the error on the line A.getClass(); even though I don't think it should.That line isn't in the code you posted. The same thing applies really: post a brief example that gives the runtime error along with the exact stack trace that is produced.

  • De-serialization not calling default constructor ??

    Hi,
    I have a strange problem with serialization (de-serialization, actually):
    I have a bunch of classes that represent the model for my application.
    These classes are organized as a complex tree and come in three flavors:
    public abstract class AbstractIOCLeaf implements IOCElement {
         private String name;
         private transient boolean changed = false;
         private transient LinkedList<ChangeListener> changeListeners;
         protected AbstractIOCLeaf() {
              super();
              name = null;
              changed = false;
              changeListeners = new LinkedList<ChangeListener>();
         } //needed for Serialzation
         protected AbstractIOCLeaf(String name) {
              this();
              this.name = name;
    ...this class is a leaf: it cannot contain other sub-elements.
    public abstract class AbstractIOCList<T extends IOCElement> extends AbstractIOCNode implements ComboBoxModel {
         protected LinkedList<T> list = null;
         protected transient List<ListDataListener> listListeners;
         protected abstract T newElement(String name);     
         protected AbstractIOCList() { super();  listListeners = new LinkedList<ListDataListener>(); }
         public AbstractIOCList(String name) {
              super(name);
              list = new LinkedList<T>();
              listListeners = new LinkedList<ListDataListener>();
    ... This class holds a list of elements that are all equal.
    and finally:
    public abstract class AbstractIOCNode extends AbstractIOCLeaf implements ChangeListener, ListDataListener {
         protected AbstractIOCNode() { super(); }
         protected AbstractIOCNode(String name) {
              super(name);
    ... This class holds elements that are all different.
    The actual classes extends one of these following the pattern:
    public class StateMachine extends AbstractIOCNode {
         private StateList states = null;;
         private EventQueue fEventQueue = null;
         private StateMachine() { super(); }
         private StateMachine(String name) {
              super(name);
              states = StateList.newInstance(this);
              changed = false;
         public static StateMachine newInstance(String name) {
              StateMachine sm = new StateMachine(name);
              sm.initialize();
              return sm;
    public class StateList extends AbstractIOCList<State> {
         private StateMachine sm;
         private StateList() { super("StateList"); sm = null; }
         private StateList(StateMachine sm) {
              this();
              this.sm = sm;
         public static StateList newInstance(StateMachine sm) {
              StateList list = new StateList(sm);
              list.initialize();
              return list;
    ...etc. etc.
    I do serialization calling ObjectOutputStream.writeObject on the root object and (obviously) deserialize using ObjectOutputStream.readObject.
    The process works, but it seems that the default constructors in particular AbstractIOCLeaf() is never called while deserializing. First hint to something amiss was the fact that I always had the transient field changeListeners remaining in its default null state.
    Further investigation involving debugging and breakpointing confirmed no default constructor is called in spite of the super(); calls.
    What am I doing wrong??
    Did I miss something about serialization (apparently so, but I cannot understand what!)?
    Side issue:
    I tried substituting ObjectOutputStream.writeObject with XMLEncoder.writeObject, but then I get the error: "Class sun.reflect.misc.Trampoline can not access a member of class com.softin.IOCbuilder.model.IOController with modifiers "private"".
    Aren't those classes supposed to be equivalent?
    Is there any (fast) way to desume the offending member?
    Excuse me for the length of the post and
    Thanks in Advance
    Mauro

    Oops, nevermind. Sorry.

Maybe you are looking for