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 8956387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:46:44+00:00 2026-06-15T14:46:44+00:00

I have a trait with abstract methods and concrete implemented methods, so something like

  • 0

I have a trait with abstract methods and concrete implemented methods, so something like this:

trait MyTrait extends BaseClass {
    def myAbstractMethod: MyReturnType
    def myConcreteMethod = { /*implementation*/ }
}

Now I mixin the trait:

class MyClass extends BaseClass with MyTrait {

}

The BaseClass does not implement the abstract method. I expected the scala compiler to enforce that the abstract method must be implemented (just like a Java interface) when I mix in the trait. But there is no compiler error.

My particular case is more complicated. I was not able to test what happens at runtime, yet.

  1. Why doesn’t the scala compiler enforce the implementation of the abstract method?
  2. Can I make the scala compiler enforce the implementation of the abstract method?
  3. Must I add abstract or override somewhere?
  4. What happens at runtime when I try to create and use instances of MyClass?
  • 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-06-15T14:46:45+00:00Added an answer on June 15, 2026 at 2:46 pm

    You should definitely get a compiler error…

    scala> :paste
    // Entering paste mode (ctrl-D to finish)
    
    trait MyTrait extends BaseClass {
        def myAbstractMethod: MyReturnType
        def myConcreteMethod = { /*implementation*/ }
    }
    
    class MyClass extends BaseClass with MyTrait {    
    }
    
    
    // Exiting paste mode, now interpreting.
    
    <console>:14: error: class MyClass needs to be abstract, since method myAbstractMethod in trait MyTrait of type => MyReturnType is not defined
           class MyClass extends BaseClass with MyTrait {
    
    
     ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Considering: abstract class Base { def something() = println(Base) } trait TraitA extends Base
I have a trait and an implementation looking like: trait Foo[A] { def bar[B
I have this trait trait NonBlockingGoodness extends DataStore { import akka.dispatch.{ Future, ExecutionContext }
Assume, we have: class B class A extends B trait T Then it holds:
I have the following code implementation of Breadth-First search. trait State{ def successors:Seq[State] def
I have this play framework 2 code (simplified): import formatters.json.IdeaTypeFormatter._ object IdeaTypes extends Controller
I have the following code defining a type class. trait Foo[T] { def toFoo(x:
I would like to have a sealed trait which have a declared method that
Suppose I have the following trait with two abstract vals trait Base { val
Hello I have the follwong : trait CarObject{ val name: String } def takeCarObject(obj:CarObject)

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.