This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes conversion question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "conversion question" Watch "conversion question" New topic

conversion question

Serge Batov

Joined: Jul 11, 2002
Posts: 1
Hi, I do not understand that this following code compiles just fine

char c = 5;
int i = 10;
c +=i;
But this
char c = 5;
int i = 10;
c = c + i;
give a compile error: possible loss of precision...
What's a difference between those two assignments?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
See here. A compound assignment operator like += includes an implied cast, which is missing in your second example.

"I'm not back." - Bill Harding, Twister
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Knew I was forgetting something...
wood burning stoves
subject: conversion question
jQuery in Action, 3rd edition