File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Hi Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Hi

sambasivarao laghuvarapu
Greenhorn

Joined: Jun 07, 2007
Posts: 9
class Test {

public static void main(String[] args) {
m1();
}
static byte m1( ) {
final char c1 ='2';
return c1; //line 1
}
static byte m2(final char c2) {
c2='3';
return c2; //line 2
}
}

while i am compiling this code i am getting compiler error at line 2.please anybody help me
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Greetings,

The problem is that the method m2 is declared to return a byte yet it actually returns a char. A char is a 16 bit unsigned number and a byte is an 8 bit signed number so a char doesn't fit into a byte.

One solution is to declare the method m2 to return a char.

Kaydell
[ September 02, 2007: Message edited by: Kaydell Leavitt ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11313
    
  16

as a general tip, when you post a question like "I'm getting a compiler error", it helps TREMENDOUSLY if you post the ACTUAL error you are getting.

and believe it or not, those compiler error do actually tell you what the problem is. learning to read them is a valuable skill.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11313
    
  16

and, since this is a duplicate, i'm closing this one. Please follow up in the other thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hi