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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:47:52+00:00 2026-05-25T02:47:52+00:00

Suppose there are class/trait definitions as follows: trait T1 {} trait T2 {} abstract

  • 0

Suppose there are class/trait definitions as follows:

trait T1 {}
trait T2 {}
abstract class A{}

class B {}
class C extends A with T1 with T2 {}

val b = new B with T1
val c = new C

Given the instance of b and c, how do I get their inheritance information (i.e. to know that b implements T1, and c implements A, T1 and T2) ?

Thanks for your help.

  • 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-25T02:47:53+00:00Added an answer on May 25, 2026 at 2:47 am

    If you don’t know the type of the object (you have some AnyRef) and just want to test whether it’s instance of some class or trait, then you can use isInstanceOf:

    b.isInstanceOf[T2]
    

    If you then want to cast it to that type, then use asInstanceOf

    b.asInstanceOf[T1]
    

    From the other hand, if you don’t know what you are searching for, then you can try to use Java reflection. To get list of implemented traits and interfaces use:

    c.getClass.getInterfaces
    

    To get superclass use:

    c.getClass.getSuperclass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose there is this code: class CFoo { public: CFoo() { iBar = new
Suppose there in an interface Displaceable and a class Circle which implements Displaceable. Displaceable
We say that java follows a single inheritance model i.e. a Java class can
Suppose that I want to write a case class Stepper as follows: case class
Suppose there is a C++11 API that uses enum classes: // api.hpp enum class
Suppose we have a class named Calculator . There's a class method in it,
Suppose I have the following code: trait Trait1 { trait Inner { val name
Suppose there is a tiny class template<class T1> class c { template<class T> class
Suppose there is a input file. The file contains php class with many functions

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.