Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9202639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:18:14+00:00 2026-06-17T23:18:14+00:00

Possible Duplicate: Eclipse bug? When is a short not a short? In Java I

  • 0

Possible Duplicate:
Eclipse bug? When is a short not a short?

In Java I can assign a short or a byte inside blocks like this:

short s = 20000;
byte  b = 120;

Because 20000 is a short value and 120 is a byte value, if I attempt to try:

short s = 67000;
byte  b = 128;

I will get an error that states it cannot compile from int to byte where

byte b = (byte)12232;

will not even trigger a warning that value may get lost. In a function call I’m forced to cast it anyways:

void test(short s){}
test(1) //invalid
test((short)1) //valid

While on return types it is okay again.

short test(){
    return 1; //valid
}

Why does the compiler sometimes deside to know the bounds of numbers (at least from constants), while it seem that it forgets it elsewhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:18:16+00:00Added an answer on June 17, 2026 at 11:18 pm

    Integral numeric literals in Java are of just two kinds: int (which are declared as 123), and long (which are declared as 123L).

    • short s = 1 is allowed because it is an assignment and a narrow conversion is allowed there
    • short s = 67000 doesn’t work because you are exceeding the maximum value that can rapresented with a short
    • short s = (short)67000 works because you are placing a cast so you are explicitly requesting the type checker to ignore the fact that 67000 exceeds the maximum value
    • test(1) doesn’t work because it’s a method invocation, a narrow conversion is not allowed (int -> short) and 1 is always evaluated as an integer literal by the compiler
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Developing for Android in Eclipse: R.java not generating what to do if
Possible Duplicate: Why are Exceptions not Checked in .NET? Coming from Eclipse/Java, I noticed
Possible Duplicate: Developing for Android in Eclipse: R.java not generating I cleaned my project
Possible Duplicate: Developing for Android in Eclipse: R.java not generating Im using Ubuntu 12.04
Possible Duplicate: Developing for Android in Eclipse: R.java not generating I have imported a
Possible Duplicate: Developing for Android in Eclipse: R.java not generating I have a one
Possible Duplicate: NoClassDefFoundError - Eclipse and Android I'm seeing this question is getting asked
Possible Duplicate: Can I run from command line program created by Eclipse? I am
Possible Duplicate: Eclipse error: Editor does not contain a main type I am currently
Possible Duplicate: Downloading Eclipse’s Source Code I have known that I can get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.