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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:24:26+00:00 2026-06-06T04:24:26+00:00

I have a class like this: abstract class CrudResource extends Controller { type ResourceIdType

  • 0

I have a class like this:

abstract class CrudResource extends Controller {
  type ResourceIdType


  def getAction(id: ResourceIdType) = ...
  def deleteAction(id: ResourceIdType) = ...

  ...
}

which is intended to be used like so:

class Payees extends CrudResource {
  type ResourceIdType = Int

  ...
}

I’d like to default the ResourceIdType to Int, like so:

abstract class CrudResource extends Controller {
  type ResourceIdType = Int

  ...
}

so that the ID type will be Int unless a subclass overrides it like so:

override type ResourceId = String

but this fails to compile with:

error: overriding type ResourceIdType in class CrudResource, which equals Int;
 type ResourceIdType has incompatible type
       class Payees extends CrudResource { override type ResourceIdType = String }

Is it possible to do what I’m trying to do? I tried, in CrudResource, type ResourceIdType <: Any = Int, but that’s not valid syntax.

  • 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-06T04:24:27+00:00Added an answer on June 6, 2026 at 4:24 am

    That would be a violation of the liskov substitution principle. Let’s assume you can do it.

    abstract class CrudResource extends Controller {
      type ResourceIdType = Int
      def resources: List[ResourceIdType] = ???
      def getAction(id: ResourceIdType) = ???
      def deleteAction(id: ResourceIdType) = ???
    }
    
    class Payees extends CrudResource {
      override type ResourceIdType = String
    }
    
    class Trouble {
      var resource: Controller.ResourceIdType
    }
    val trouble = new Trouble
    val crudResource: CrudResource = new Payee
    trouble.resource = crudResource.resources.head // assigning String to Int var!
    

    However, you are halfway to a cake pattern. If you define ResourceId as an abstract nested class, you could have subclasses implementing them in terms of Int or String, as long as its API doesn’t expose the specific types.

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

Sidebar

Related Questions

I have a (Java) class with operations like this: abstract class Holder { def
Say I have code like this: abstract class Animal[T <: Animal[T]] { def mateWith(that:
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have a model that looks something like this: public abstract class Parent {
I have an abstract class BaseItem declared like this: public abstract class BaseItem {
Let's say I have something like this: abstract class Parent { protected function foobar($data)
If I have an abstract class like this: public abstract class Item { private
I have a set of classes something like this: abstract class CollectionAbs implements Iterator
I have 4 classes, one Database helper and 3 defined like this: abstract class
I have an interface Tree and an abstract class RBTree which implements this interface.

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.