-2

Im seeing this quite a bit lately, especially in android development.

Some examples would be:

byte myByte = (byte) stream.read();

or

TextView tView = (TextView) findViewById(R.id.textView);

What I don't understand is what the (byte) / (TextView) part is for.

EDIT: Excuse me if this is a duplicate, I had no idea how to call this or what to search for.

Mario Geuenich
  • 294
  • 1
  • 7
  • 17

1 Answers1

1

What you are seeing is a Type cast. You want to handle a specific Type in your program and tell the Compiler that it is safe to treat something just the way you describe it as.

Since YOU are the one who is telling the Compiler that it is safe to assume that this treatment is correct, it is entirely your responsibility to ensure it as well and is therefore rather unsafe

Julian
  • 525
  • 5
  • 19