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

  • Home
  • SEARCH
  • 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 6640467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:40:33+00:00 2026-05-25T23:40:33+00:00

I have a mixin class that bundles functionality for different types that do not

  • 0

I have a mixin class that bundles functionality for different types that do not share a common heritage. The mixing is applied using the @Mixin annotation, so it is handled at compile time.

Some of the mixin methods return this as the result of a method call. The problem is that the this is of the mixing type and not the type of the base class. When I want to work typed in the rest of the application a ClassCastException is thrown saying that the mixing type can not be cast to the base type.

In the example code below return this returns an object of type AMixin instead of an Object of type BaseClass.

How can I have return this return an object of type BaseClass instead of an object of type AMixin?

class AMixin {

  def getWhatIWant(){
    if(isWhatIwant){
      return this
    } else {
      getChildWhatIWant()
    }
  }

  def getChildWhatIWant(){
    for (def child in childred) {
        def whatIWant = child.getWhatIWant()
        if (whatIWant) {
            return whatIWant
        }
    }
    return null
  }
}


@Mixin(AMixin)
class BaseClass {
  boolean isWhatiWant
  List<baseClass> children
}
  • 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-25T23:40:34+00:00Added an answer on May 25, 2026 at 11:40 pm

    I just ran into this same situation. I solved it by setting ‘this’ from the concrete class into a private variable ‘me’ inside the concrete class and return ‘me’ in the Mixin classes. For example:

    class MyMixin {
        def mixinMethod() {
            // do stuff
            return me
        }
    }
    
    @Mixin(MyMixin)
    class MyConcreteClass {
        private MyConcreteClass me
        MyConcreteClass() {
            me = this
        }
    }
    

    I feel like it’s a bit kludgy, but I think it’s a lot simpler than this other solution. I personally need the ability to use the same Mixin in multiple classes, and it sounds like this other proposed solution would not allow for that if you cannot assign multiple Categories to a single Mixin class.

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

Sidebar

Related Questions

Say I have two traits that I would like to mixin to a class.
I have read some posts on here about not mixing parameters when passing into
I have been using SmartGWT but have run into trouble mixing SmartGWT with other
At work we have a base class, let's call it IntrusiveBase, that acts something
I have a QueueProcessor class that processes a work queue. I want to send
I have a category class that I want to Use that acts on a
I was writing some code where I have a class that can accept mixins
I am using LESS and im trying for a type of mixin. I have
I have a model using Django-MPTT that also has a field for using a
I have several functions on graph f(), g() and h() that implements different algorithms

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.