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 7624691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:01:46+00:00 2026-05-31T05:01:46+00:00

This is something I never truly understood in Java. Lets say I have: int

  • 0

This is something I never truly understood in Java. Lets say I have:

int x = 4;

now I can not do this

functionThatRequiresString(x) or functionThatRequiresString((String)x)

Now I can not pass a function that requires a string the variable x. I am also unable to cast it from an int to a string. Now the normal ways of doing this would be:

Integer.toString(x) or String.valueOf(x)

Now why can I do this though?

functionThatRequiresString(""+x)

How is this different from casting an integer to a string?

  • 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-05-31T05:01:48+00:00Added an answer on May 31, 2026 at 5:01 am

    Casting means that you tell the compiler “I have an object of type A here, but I want you to treat it as if it is of type B. Don’t give an error because it doesn’t look like a B to you”.

    Casting does not do any conversions (at least not for non-primitive types). If, when running the program, the object really is not of type B, you will get a ClassCastException.

    You cannot cast an int to a String because an int is simply not a String – you can tell the compiler to pretend that it is, but you’ll get a ClassCastException when you run the program.

    The other examples you give will convert (not cast) an int to a String.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is something that I never ran into before. Say I have a class
this is something I have always had confusion about I never can seem to
This is something that I have never fully grasped in .NET as to the
This is something I've pseudo-solved many times and have never quite found a solution
This is something that I have always wondered about, but never bothered to profile.
I have never worked with web services and rails, and obviously this is something
This is something I've never seen done, and I'm not turning up in my
This is something that has always bothered me about PHP and I have never
Let's say my app does something unrecoverable (this never happens, right? :P ). Should
i have never tried something like this so i need your help. i have

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.