• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How To Decide Compile Time constant?

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In above program at line->6 50 is compile time
constant this is why method accepts it
even though method return byte.

I know that 50 is final and is in ranger of byte
this is why it is compile time constant.

By at line->10 100 is not compile time constant why.
how will i decide that 100 is not compile time constant
but 50 is.
 
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by gowher amin naik:

In above program at line->6 50 is compile time
constant this is why method accepts it
even though method return byte.

I know that 50 is final and is in ranger of byte
this is why it is compile time constant.

By at line->10 100 is not compile time constant why.
how will i decide that 100 is not compile time constant
but 50 is.



Because in your class there is no where any method exist named as "method(int)" which is accpeting an int parameter if you really want to run the program then you have to explicitly typecast to 100.

and call method as follows

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
100 is a compile-time constant.

That is not the issue here.

The issue is the difference between method invocation conversion and assignment conversion.

Assignment conversion includes the narrowing primitive conversions.

Method invocation conversion doesn't include the narrowing primitive conversions.
[ August 01, 2006: Message edited by: Keith Lynn ]
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ok Ankur check code 2
method return x which is int but compile time constant
hence it works.
variable a is also int but compile time constant but it does not work
there is compile time error at Line->10
why
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method invocation conversions specifically do not include the implicit narrowing of integer constants which is part of assignment conversion. The designers of the Java programming language felt that including these implicit narrowing conversions would add additional complexity to the overloaded method matching resolution process.
 
reply
    Bookmark Topic Watch Topic
  • New Topic