aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "conversion question" Watch "conversion question" New topic
Author

conversion question

Serge Batov
Greenhorn

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
Wanderer
Sheriff

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
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Serge,
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
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Knew I was forgetting something...
 
 
subject: conversion question