Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion drops a constructor #53

Open
dnadolny opened this issue Jun 18, 2013 · 3 comments
Open

Conversion drops a constructor #53

dnadolny opened this issue Jun 18, 2013 · 3 comments

Comments

@dnadolny
Copy link
Contributor

Starting from the Java:

class A {
    public A(String str) {}
}
class B extends A {
    public B() {
        super("some value");
    }
    public B(String str) {
        super(str);
    }
}

Converting the class B gives:

  class B extends A {
    def this(str: String) {
      super(str)
    }
  }

The default constructor that called super("some value") is silently dropped.

@dnadolny
Copy link
Contributor Author

Another case of a dropped constructor:

public class A extends B<String, Map<String, Double>> {
   private static final long serialVersionUID = 1L;

   public A() {
      super(new C<Map<String, Double>>() {
         public D<String, Double> z() {
            return new E<String, Double>(0.0);
         }
      });
   }
}

becomes:

@SerialVersionUID(1L)
class A extends B[String, Map[String, Double]]

timowest added a commit that referenced this issue Jun 20, 2013
@timowest
Copy link
Owner

The constructor usage optimization is not yet perfect, the sources are here https://github.com/mysema/scalagen/blob/master/scalagen/src/main/scala/com/mysema/scalagen/Constructors.scala

I don't think there is a valid way to convert the first example to Scala, but the second example should work

@dnadolny
Copy link
Contributor Author

Technically the first one could be (class B(str: String) extends A(str) { def this() = this("some value") }), although to do that would require knowing that the literal "some value" is a String, and that the B(String str) constructor doesn't do anything not done by B() (which, in this case, is just nothing).
It's probably not worth it to attempt to fix it, but how about putting a comment /* Unconverted constructor: (original Java here, or at least the signature) */, or something to that effect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants