Results 1 to 12 of 12
Like Tree3Likes
  • 2 Post By Tolls
  • 1 Post By gimbal2

Thread: is there any way to stop the compiler from calling a constructor implicitly?

  1. #1
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Default is there any way to stop the compiler from calling a constructor implicitly?

    is there any way to compile a program without calling constructor.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    Are you by any chance confusing compiling and executing?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    no i mean that whenever we compile the program an implicit constructor is called to that initializes all the non static variable to their default values, so i just want not to call that constructor either implicitly not explicitly, is there any way to do that?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    No. When you compile a Java class, bytecode is generated. Nothing is 'called' or 'initialized.'

    All fields, whether static or instance, have default values -- zero for numeric primitives, false for boolean and null for reference types.

    I think you need to describe the problem for which you think a solution would be to not initialize variables.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    Quote Originally Posted by DarrylBurke View Post
    No. When you compile a Java class, bytecode is generated. Nothing is 'called' or 'initialized.'

    All fields, whether static or instance, have default values -- zero for numeric primitives, false for boolean and null for reference types.

    I think you need to describe the problem for which you think a solution would be to not initialize variables.

    db
    db have you ever open the bytecode? As per my knowledge all the non static variables are initialize with that implicit constructor, once i opened a bytecode and there was a constructor which i didn't define. so it mean that constructor must be there for some reasons, i don't exactly for what?

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    You're miswriting and misreading - DB is pointing out that the compiler does not call any constructor like you said in post 3. It may generate one if you don't provide any constructor yourself and that generated constructor may indeed at some point in time be called - when the application is being executed by the Java runtime, long after everything is compiled and packaged.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    ok sorry db but thank you both of you, but my question is still the same that implicit constructor, i don't want that constructor to be called at any point, Is there any way to skip it?

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    Quote Originally Posted by rahil.khan View Post
    ok sorry db but thank you both of you, but my question is still the same that implicit constructor, i don't want that constructor to be called at any point, Is there any way to skip it?
    That 'implicit constructor' as you call it, is it named '<cinit>'? or '<init>'?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    Since all classes in Java ultimately extend from Object then, without at least an implicit constructor call, how do you expect the underlying Object structure to be initialised?
    gimbal2 and rahil.khan like this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    Quote Originally Posted by rahil.khan View Post
    ok sorry db but thank you both of you, but my question is still the same that implicit constructor, i don't want that constructor to be called at any point, Is there any way to skip it?
    Yes you do - it is not Java that needs to be corrected here, it is your expectations and understanding of the situation. I'm going to not beat around the bush in the next sentence, beware:

    If you have a code design that becomes problematic because Java is performing a vital function of the platform, then change your code design so it doesn't suck anymore.
    DarrylBurke likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    Instead of asking questions whether Java or the compiler can do this or that, why not tell use why you want to do it. Perhaps we can offer a better solution.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    rahil.khan is offline Member
    Join Date
    Oct 2014
    Location
    NEW DELHI
    Posts
    41
    Rep Power
    0

    Default Re: is there any way to stop the compiler from calling a constructor implicitly?

    you are getting me wrong i just want to know whether we can do that or not, by all your last replies its clear that there no way to skip it. Thank you so much guys... its always very helpful to be here... and going through this forum is just awesome...

Similar Threads

  1. Compiler error on constructor for thread class
    By ireland94 in forum Threads and Synchronization
    Replies: 2
    Last Post: 05-09-2013, 07:57 PM
  2. Replies: 6
    Last Post: 08-21-2012, 03:37 AM
  3. Default constructor by compiler.
    By manishdivs in forum New To Java
    Replies: 2
    Last Post: 09-19-2011, 06:31 PM
  4. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •