Git Product home page Git Product logo

Comments (2)

ahoy-jon avatar ahoy-jon commented on June 30, 2024 1

Thank you so much for explaining it.

And it's easy to go around, we can create a case class that extends the trait.

case class Def1Container(toto : Option[String]) extends Def1

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on June 30, 2024

Yes: there is no non-controversial way to do it. trait and abstract class have no normal (non-abstract) constructors, that were defined with the intent to construct a fully initialized object. To instantiate trait we would have to:

  • create an anonymous class
  • find all abstract members of it
  • check if their visibility would even allow us to implement them
  • basically guess what would be their implementations
  • put the implementations in the anonymous class, hoping that there are no assert or other runtime surprises
  • if all abstract members would be vals or nullary defs, perhaps that would be doable
  • if there would be any def which takes arguments, we would be pulling implementations out of thin air

So, it would be:

  • rather hard to implement
  • only possible for some special cases, which isn't very predictable
  • feel even more magical, while one of the things we have to fight, is the argument that nobody understands where the transformation comes from and so it cannot be trusted
  • quite error prone.

Perhaps if #192 would be implemented, than you could provide a function constructing such trait yourself and it would be non-ambiguous how it works. With features we have now we do not add support for case which would give users more troubles than benefits.

Of course the above is only about "open" traits. sealed traits are supported and any sane data model uses traits only as sealed traits, leaving non-sealed for interfaces, services, etc.

from chimney.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.