Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable arguments

 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The 11th line is compiling error, but the 10th line is OK, why ? How does the compiler understanding them ? Thank you !
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the compile time error? Tell us the details - it makes life much easier for all of us.
 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:And what is the compile time error? Tell us the details - it makes life much easier for all of us.


The following Screenshot:
Screenshot-21.png
compile error
[Thumbnail for Screenshot-21.png]
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, you get that error when there are two different methods that match the call, and the compiler has no rule to determine the priority.

The key point here are:
- 1 is an int. This can automatically be converted to a float. It can't be autoboxed to a Character.
- 'a' is a char, which is an integer type. Which means it can be autoboxed to a Character, but it can also be converted to a float.

This means that line 10 can match test(float, Character...), but it can't match test(Character...), because 1 can't match Character. So there's no ambiguity.

However, line 11 can match both. At this point the compiler checks its rules for prioritising. These can get a bit complicated (read the Java Language Specification for the full rules), but it turns out that none of them can be applied in this case. So the compiler doesn't know what to do, and you get the error.
 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:OK, you get that error when there are two different methods that match the call, and the compiler has no rule to determine the priority.

The key point here are:
- 1 is an int. This can automatically be converted to a float. It can't be autoboxed to a Character.
- 'a' is a char, which is an integer type. Which means it can be autoboxed to a Character, but it can also be converted to a float.

This means that line 10 can match test(float, Character...), but it can't match test(Character...), because 1 can't match Character. So there's no ambiguity.

However, line 11 can match both. At this point the compiler checks its rules for prioritising. These can get a bit complicated (read the Java Language Specification for the full rules), but it turns out that none of them can be applied in this case. So the compiler doesn't know what to do, and you get the error.


Thank you very much, I understand.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic