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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:11:23+00:00 2026-05-25T22:11:23+00:00

Why is it possible to override an empty-parentheses method with an object ? trait

  • 0

Why is it possible to override an empty-parentheses method with an object?

trait A {
  def meth = {}
  def meth_p() = {}
}

class B extends A {
  object meth_p
} // compiles

Overriding the method without parentheses does not compile:

class B1 extends A {
  object meth
} // does not compile

Neither do any of the following combinations work (without override modifier):

class BX extends A {
  // of course, each declaration should get its own class
  def meth = {}
  def meth_p() = {}
  def meth() = {}
  def meth_p = {}
  val meth = {}
  val meth_p = {}
  // ...
}

Is this documented and useful behaviour? I’ve just run into a very subtle bug because of this accidental override.

  • 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-25T22:11:24+00:00Added an answer on May 25, 2026 at 10:11 pm

    This sure as hell looks like a bug. If you do this the other way around it just gets weirder.

    class A {
       object m { override def toString = "object m" }
    }
    
    class B extends A {
       def m() = "def m"
    }
    
    scala> (new A).m
    res0: object A#m = object m
    
    scala> (new A).m() // doesn't compile
    
    scala> (new B).m
    <console>:10: error: ambiguous reference to overloaded definition,
    both method m in class B of type ()java.lang.String
    and  object m in class A of type object B#m
    match expected type ?
                  (new B).m
                          ^
    scala> (new B).m()
    java.lang.VerifyError: class B overrides final method m.()LA$m$;
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClassCond(Unknown Source)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at scala.tools.nsc.interpreter.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:52)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at scala.tools.nsc.interpreter.AbstractFileClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(AbstractFileClassLoader.scala:17)
            at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:50)
            at scala.tools.nsc.interpreter.AbstractFileClassLoader.loadClass(AbstractFileClassLoader.scala:17)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at .<init>(<console>:10)
            at .<clinit>(<console>)
            at .<init>(<console>:11)
            at .<clinit>(<console>)
            at $print(<console>)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
            at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
            at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
            at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
            at java.lang.Thread.run(Unknown Source)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is possible in plain Java to override a method of a class programmatically
Is it at all possible to override a private method of a super class
I want to override the Tostring() method for changing some characters. Is it possible?
Is it possible to override the to_sentence method just for one model in my
Is it possible to override an attibute set on a partial class? So I
Is it possible to override ONLY CERTAIN functions from an exisiting delegate, without ourself
Is it possible to override default value of WebClientProtocol.Timeout property via web.config? <httpRuntime executionTimeout=500
Is it possible to override the background color of the minimize and maximized buttons
Is it possible to override reflection functionality ?
Is it possible to override a generisized function as illustrated in the code snippet

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.