Results 1 to 12 of 12
- 11-13-2014, 06:06 AM #1
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
- 11-13-2014, 06:43 AM #2
Re: is there any way to stop the compiler from calling a constructor implicitly?
Are you by any chance confusing compiling and executing?
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 11-13-2014, 07:58 AM #3
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
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?
- 11-13-2014, 08:10 AM #4
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.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 11-13-2014, 08:25 AM #5
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
Re: is there any way to stop the compiler from calling a constructor implicitly?
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?
- 11-13-2014, 09:20 AM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 12
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
- 11-13-2014, 09:29 AM #7
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
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?
- 11-13-2014, 10:06 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
- 11-13-2014, 10:07 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
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?
Please do not ask for code as refusal often offends.
** This space for rent **
- 11-13-2014, 10:11 AM #10
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 12
Re: is there any way to stop the compiler from calling a constructor implicitly?
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."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 11-13-2014, 04:29 PM #11
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 11-13-2014, 06:12 PM #12
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
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
-
Compiler error on constructor for thread class
By ireland94 in forum Threads and SynchronizationReplies: 2Last Post: 05-09-2013, 07:57 PM -
How to stop JSP Execution if class constructor failed
By KingdomX in forum New To JavaReplies: 6Last Post: 08-21-2012, 03:37 AM -
Default constructor by compiler.
By manishdivs in forum New To JavaReplies: 2Last Post: 09-19-2011, 06:31 PM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 10:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 10:01 AM
Bookmarks