Return to Video

How to Cast - Intro to Java Programming

  • 0:00 - 0:03
    That's a bit of a pain. Here is how you convince
  • 0:03 - 0:06
    the Java compiler to do it anyway. This is a very strange
  • 0:06 - 0:10
    syntax, whose origins are somewhere in the mist of time of
  • 0:10 - 0:13
    programming languages and we won't dwell on that. But here is what
  • 0:13 - 0:16
    you need to do. This value here, is of type double.
  • 0:16 - 0:18
    Now we don't want it to be in double. We want it
  • 0:18 - 0:21
    to be in integer. And then you have to put the
  • 0:21 - 0:25
    name of the type that you want and, put parentheses around it.
  • 0:25 - 0:27
    And put it before the expression you want to
  • 0:27 - 0:31
    convert. What now happens is, this expression here is
  • 0:31 - 0:35
    computed. The fractional part is discarded. The integer
  • 0:35 - 0:39
    part, is moved over here. This operation is called
  • 0:39 - 0:42
    a cast. That's a curious name, are we
  • 0:42 - 0:46
    casting out a fishing rod? Is it cast around
  • 0:46 - 0:51
    a broken a foot? The cast of characters in a play? Well I guess it's mostly like
  • 0:51 - 0:54
    the latter, becaues we have this value here.
  • 0:54 - 0:57
    That actually is a, fractional number and we want to
  • 0:57 - 1:00
    cast it, not as the hero in the play
  • 1:00 - 1:02
    but as an integer. Whatever, that's just what it's
  • 1:02 - 1:05
    called. Every once in a while, you need
  • 1:05 - 1:08
    to do this. You have, something that's not of
  • 1:08 - 1:11
    the type that you want, you want to change its
  • 1:11 - 1:14
    type and, the cast notation does that for us.
タイトル:
How to Cast - Intro to Java Programming
概説:

more » « less
Video Language:
English
Team:
Udacity
プロジェクト:
cs046: Intro to Programming
Duration:
01:15

English subtitles

改訂 Compare revisions