Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6238561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:14:17+00:00 2026-05-24T11:14:17+00:00

When trying to compile the following code with Scala 2.8.1/JavaFx 2.0 beta new KeyValue(circle.translateYProperty,

  • 0

When trying to compile the following code with Scala 2.8.1/JavaFx 2.0 beta

new KeyValue(circle.translateYProperty, random() * height)

I get the following error:

[error]  found   : javafx.beans.property.DoubleProperty
[error]  required: javafx.beans.value.WritableValue[Any]
[error]             new KeyValue(circle.translateYProperty, random() * height)
[error]                                 ^
[error] one error found

Whereas this line gets compiled just fine:

new KeyValue(circle.translateXProperty.asInstanceOf[WritableValue[Any]], random() * width)

I checked the KeyValue constructor and it has the following signature:

public <T> KeyValue(javafx.beans.value.WritableValue<T> tWritableValue, T t) { /* compiled code */ }

circle.translateXProperty returns DoubleProperty which implements the following interface:

public interface WritableNumberValue extends javafx.beans.value.WritableValue<java.lang.Number>

What would be more elegant solution than casting to make it compile?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:14:18+00:00Added an answer on May 24, 2026 at 11:14 am

    — Revised answer, based on Exception and Blaisorblade’s comments —

    You’ve hit a limitation of Scala’s application of implicits, rather than (just) a Scala-Java interop problem. Here’s a simplified example,

    class Foo[T]
    def f[T](x: Foo[T], y: T): T = y
    
    f(new Foo[Number], new java.lang.Double(0)) // OK; infers T==Number
    f[Number](new Foo[Number], 0)               // OK; uses implicit int2Integer(0)
    // f(new Foo[Number], 0)                    // error
    
    • The first call to f works because the common supertype of java.lang.Double and java.lang.Number is java.lang.Number, so that is the type inferred for T.

    • The second call to f works because we’ve explicitly told the compiler that T==java.lang.Number. When the compiler finds the second argument, 0 : Int, doesn’t match the expected type java.lang.Number, it searches for an implicit conversion from Int to Number. The compiler finds Predef.int2Integer and applies it. All is well.

    • The third call to f doesn’t work, because the first parameter constrains T == Number, and the second argument says T >: Int (that is, T is a supertype of Int). The common supertype of Int and Number is Any, but that won’t work because Foo[T] is not covariant in T (in other words, we can’t cast a Foo[Number] to a Foo[Any]). That’s the gist of the compiler’s error message. Note that the compiler doesn’t know how to apply an implicit conversion, because it doesn’t know a specific type of T to convert to.

    One strange thing about the JavaFX code that you posted is that the KeyValue class is not generic, but is has a generic constructor. Interestingly, this is not possible in Scala, so there’s no way (as far as I can tell), to explicitly constrain the parameter T from Scala code. If the entire KeyValue class were generic, you’d also be able to write

    new KeyValue[Number](circle.translateYProperty, random() * height)
    

    which would be equivalent to the code that Exception posted, since the compiler would infer the double2Double conversion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile the following code however I get an error on the
I am trying to compile the following code and i am getting the error:
I'm getting an error on compile with the following code. I'm trying to call
When trying to compile the following code, I am getting a warning that line
I am trying to compile my gcc code using the following make command .
I'm trying to compile some code which contains the following declaration, because I would
I am trying to compile following code in C#: String[] words = {Hello, Worlds};
When trying to compile the following code in LINQPad : void Main() { DriveInfo.GetDrives().Select(GetProviderName).Dump();
while trying to compile the following code in OpenCV2 in linux, cv::Mat image1, image2;
I'm getting a segmentation fault trying to compile the following code. My question is,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.