java-design-patterns icon indicating copy to clipboard operation
java-design-patterns copied to clipboard

Casting Issue

Open MaheshMadushan opened this issue 2 years ago • 4 comments

CB

MaheshMadushan avatar Jan 30 '22 02:01 MaheshMadushan

@MaheshMadushan can you explain what this issue is about?

iluwatar avatar Feb 12 '22 18:02 iluwatar

Hi @iluwatar , There is a small casting issue. image

MaheshMadushan avatar Feb 15 '22 01:02 MaheshMadushan

Hi @MaheshMadushan @iluwatar . I'm beginner in java and during learning the java literals , I encountered one nice point which address this issue . In java integer literal can always be assigned to a long variable . However , to specify a long literal you will need to explicitly tell the compiler that the literal value is of type long . We can do this by appending an uppercase or lowercase L to the literal . Here in this case we have variable futureTime as type of long type but the literal assigned to it is of type integer . So here compiler first do the casting of 1000 * 1000 * 1000 * 1000 to an integer literal and then assigned it to futureTime . Solution to this problem is to use the long literal. For example :

  • 1000L * 1000 * 1000 * 1000
  • 1000 * 1000L * 1000 * 1000
  • 1000 * 1000 * 1000L * 1000
  • 1000 * 1000 * 1000 * 1000L These are few valid long literal we can use ( we can also use variation like 1000000000000L ) . I hope you got my point here .

Yashwant-Tailor avatar Feb 16 '22 20:02 Yashwant-Tailor

I want to fix this issue! Thanks a lot. @iluwatar

xyllq999 avatar May 09 '22 08:05 xyllq999

Hi is this issue still up for taking, or is it closed? I would like to contribute

rushisuper avatar Sep 06 '22 18:09 rushisuper

Fixed with https://github.com/iluwatar/java-design-patterns/pull/1994

iluwatar avatar Sep 10 '22 13:09 iluwatar