• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding passing the value  RSS feed

 
laxmidhar prad
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir
suppose i write a programme.in this i declare a method whch take integer as an argument.in my main method i want to call this method by passing short. is it possible or not
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, simply cast the short to an integer. Like this:

public void main(String[] args)
{
// your code

yourMethod((int)(x)); //where x is the short you are describing
}
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When converting from a short to an int, you don't need a cast at all. Java automatically does the conversion, because a short always fits into an int.
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good call, sorry for the bad advice
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!