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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:44:26+00:00 2026-06-15T18:44:26+00:00

I have a scala function with the following signature: def getValue: Validation[ Throwable, String

  • 0

I have a scala function with the following signature:

def getValue: Validation[ Throwable, String ]

Now, I want to process in Java the result (say res) of calling this function.

I can call res.isSuccess() and res.isFailure() but how do I extract the underlying Throwable or success String ?

I tried casting but testing (res instanceof scalaz.Failure) results in a scalaz.Failure cannot be resolved to a type (the scala and scalaz jars are visible)

Is there a generic way of doing this for Validation, Option, Either, etc… ?

EDIT I realize I can probably use a fold but that would lead to a lot of ugly boilerplate code in Java (which does not need more). Anything better looking ?

  • 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-15T18:44:27+00:00Added an answer on June 15, 2026 at 6:44 pm

    Success and Failure are both case classes:

    final case class Success[E, A](a: A) extends Validation[E, A]
    final case class Failure[E, A](e: E) extends Validation[E, A]
    

    So you can write the following, for example:

    import scalaz.*;
    
    public class Javaz {
      public static void main(String[] args) {
        Validation<Throwable, String> res = new Success<Throwable, String>("test");
    
        if (res.isSuccess()) {
          System.out.println(((Success) res).a());
        } else {
          System.out.println(((Failure) res).e());
        }
      }
    }
    

    For Option and Either you can use the get method (after taking the left or right projection in the case of Either).

    If at all possible it’s probably cleaner to do this kind of unwrapping with a fold, etc. on the Scala side, though.

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

Sidebar

Related Questions

I have the following function scala> def f1 = (prefix: String) => prefix +
I have the following pattern matching case in a scala function: def someFunction(sequences: Iterable[Seq[Int]]):Seq[Int]
In Scala (2.7), if I have this function: def foo(args: Array[String]) = for (arg
I have the following method: scala> def method_with_default(x: String = default) = {x +
For a numeric intensive code I have written a function with the following signature:
Take the following function: def fMatch(s: String) = { s match { case a
Suppose I have a the following in Scala object Foo { var functions: List[String
I have a function like so: def print(name:String, surname:String) { println(name + + surname)
I have the following toy function: def test[T](x: Option[List[Option[T]]]) { for (a <- x;
I have the following code in Scala-IDE: type myF = () => Boolean def

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.