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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:43:41+00:00 2026-05-31T03:43:41+00:00

Can someone explain why the output of this code is true true , instead

  • 0

Can someone explain why the output of this code is true true, instead of true false.

I would also like to know how I could achieve a output that is true false using def apply(in:Any). I’ve tried parameterised types too, and still i get true true instead of true false.

 object TestClass extends App {

  val xTrue = TypeXObject(TypeX("s"))
  val xFalse = TypeXObject(TypeY(1))
 }

 case class TypeX(string:String)

 case class TypeY(int:Int)

 object TypeXObject extends HasAbstractType{override type T = TypeX}

 object TypeYObject extends HasAbstractType{override type T = TypeY}

 abstract class HasAbstractType {
   type T
   def apply(in:Any):Any = {
     println(in.isInstanceOf[T])
     in
   }
 }

Answer:

issues.scala-lang.org/browse/SI-5042 – With article and the attached article i found that I can get the true false with manifest[T1].erasure.isInstance(t1) and manifest[T1].erasure.isInstance(t2).

  • 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-31T03:43:42+00:00Added an answer on May 31, 2026 at 3:43 am

    When I compile your code I get the following compiler message:

    [warn] there were 1 unchecked warnings; re-run with -unchecked for details
    [warn] one warning found
    

    To pass -unchecked to the compiler, I create a build.sbt containing:

    scalacOptions ++= Seq("-unchecked", "-deprecated") // (I threw in deprecated for good measure)
    

    Then when I compile, I get this enlightening warning:

    [warn] /home/lwickland/f/f.scala:18: abstract type HasAbstractType.this.T in type HasAbstractType.this.T is unchecked since it is eliminated by erasure
    [warn]     println(in.isInstanceOf[T])
    

    And at that point, I have to refer you to an excellent explanation of type erasure and how to get around it.

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

Sidebar

Related Questions

When I run this code gcc gives me the output 10. Can someone explain
Can someone explain why this script throws an exception? $byteArray = @(1,2,3) write-Output (
I don't know if anyone could kindly explain this code for me? unsigned int
Can someone please explain this to me? I have the following code: <form action=<?php
Can someone please explain why I'm getting this error? My code: def x(n): if
Can someone explain why this doesn't work like I think it should. double[] numbers1
Can someone please explain why this program outputs 0x00000004? class AndAssignment { static void
Can someone help explain the following: If I type: a=`ls -l` Then the output
Can someone explain the mechanics of a jump table and why is would be
Can someone explain this result to me. The first test succeeds but the second

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.