Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Type in parameter  RSS feed

 
winston Muijs
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow Javacoders,

I have a question regarding tHe following code.





I (almost) understand everything that is writing, but the only thing i can't get my head around is the following:

second() is of type int in the reference of processing lib. Placed in sunColorSec as a parameter. In the method def. of sunColorSec the parameter should be a float...

How is this possible?

Why can't the type be changed to int...? (the applet will not work with int for the parameter setting. Also If you change all the float to int ...not)

My mind is blank at the moment...so help me please ;)

Thanks!!

Grt,
Winston

 
Stephan van Hulst
Saloon Keeper
Posts: 7802
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Winston!

You can implicitly cast a numeric primitive to a wider primitive. That means you can assign an int to a float, because float is a wider data type.

Changing all floats to int will screw with the applet in this case, because the applet needs to perform calculations with fractional parts, and ints don't have fractional parts.
 
winston Muijs
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stephan and thanks...!

first part:
You can implicitly cast a numeric primitive to a wider primitive. That means you can assign an int to a float, because float is a wider data type.

The first part i understand. It's like in the head first java with the buckets. You can pour a little bucket into a larger one.

second part:
Changing all floats to int will screw with the applet in this case, because the applet needs to perform calculations with fractional parts, and ints don't have fractional parts.

Why does it NEED to do that in float (fractionals)...? I think i know why...because the division of ratio is a fractional...between 0 and 1.

Thanks for your answer, you have helped me a lot!

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!