This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is "compile-time constant"?" Watch "What is "compile-time constant"?" New topic

What is "compile-time constant"?

Woo Hwang

Joined: Aug 07, 2001
Posts: 13
I'm reading "Getting in touch with your Inner Class" article, I encounter a term reading a paragraph blow:
Another warning about all inner classed is that that can't declare ant static members unless they are compile-time constant and are promitives or Strings( This does not apply to static nested classed, of course)
I don't know what is compile-time constant. Can anybody tell me what it is?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Woo,
Any variable defined as final is considered to be a compile-time constant. The compiler will actually place its code in-line wherever it is used.

Woo Hwang

Joined: Aug 07, 2001
Posts: 13
Thank you for your reply. Now I understand that. But I don't know what is like "place its code in-line" . Sorry, Engllish is not my native one.
Thank you
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Think of it as a macro.
The compiler will convert MEMBER_VAR to 14. So when the code is executed you don't have a variable, you have a value (for MEMBER_VAR).

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link:
subject: What is "compile-time constant"?
It's not a secret anymore!