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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:34:49+00:00 2026-06-04T13:34:49+00:00

I am trying to use the Option.getOrElse() method but it returns etiher Any or

  • 0

I am trying to use the Option.getOrElse() method but it returns etiher Any or ScalaObject instead of an instance of the correct class that the Option was parametrized with. I can’t find any mention about this problem and it does not seem like it should be there. What am I doing wrong?

class MyClass {

  def isOk = true

}

val myVal = Some(new MyClass) // :Option[MyClass]

val check = myVal.getOrElse(false).isOk

Can’t call the isOk method because it tries calling it upon Any.

  • 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-04T13:34:51+00:00Added an answer on June 4, 2026 at 1:34 pm

    You are trying to call method isOk on base class of MyClass and Boolean (Any).

    Try this:

    scala> class MyClass(b: Boolean) { def isOk = b }
    defined class MyClass
    
    scala> val myVal = Some(new MyClass(true))
    myVal: Some[MyClass] = Some(MyClass@35d56bbe)
    
    scala> myVal.map{_.isOk}.getOrElse(false)
    res0: Boolean = true
    
    scala> myVal.getOrElse(new MyClass(false)).isOk
    res1: Boolean = true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use jQuery to check for the existence of an <option> that
I'm trying to use Twitter Bootstrap's new affix option, but I can't quite get
I am trying to use --whole-archive option, but it seems to not work with
I'm trying to use this example http://jqueryui.com/demos/autocomplete/#combobox . But it shows blank option by
I am trying to use the jquery UI draggable option handle , but not
I am trying to use jquery split function to set the option value but
I have a Scala value of type Option[Set[String]] that I am trying to use
I am trying to use the beforeSubmit option in the jQuery ajaxForm plugin to
I'm trying to use jQM-DateBox with data-option timebox in Force Clock Mode, to have
I'm trying to use PHP's split() (preg_split() is also an option if your answer

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.