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

The Archive Base Latest Questions

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

I am implementing a Java interface containing variadic methods like so: interface Footastic {

  • 0

I am implementing a Java interface containing variadic methods like so:

interface Footastic { 
  void foo(Foo... args);
}

Is it possible to implement this interface in Scala? Variadic functions are handled differently in Scala, so the following won’t work:

class Awesome extends Footastic {
  def foo(args: Foo*): Unit = { println("WIN"); }
  // also no good: def foo(args: Array[Foo]): Unit = ...
}

Is this even possible?

  • 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-25T21:05:53+00:00Added an answer on May 25, 2026 at 9:05 pm

    The code you’ve written works as-is.

    The scala compiler will generate a bridge method which implements the signature as seen from Java and forwards to the Scala implementation.

    Here’s the result of running javap -c on your class Awesome exactly as you wrote it,

    public class Awesome implements Footastic,scala.ScalaObject {
      public void foo(scala.collection.Seq<Foo>);
        Code:
           0: getstatic     #11                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
           3: ldc           #14                 // String WIN
           5: invokevirtual #18                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
           8: return
    
      public void foo(Foo[]);
        Code:
           0: aload_0
           1: getstatic     #11                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
           4: aload_1
           5: checkcast     #28                 // class "[Ljava/lang/Object;"
           8: invokevirtual #32                 // Method scala/Predef$.wrapRefArray:([Ljava/lang/Object;)Lscala/collection/mutable/WrappedArray;
          11: invokevirtual #36                 // Method foo:(Lscala/collection/Seq;)V
          14: return
    
      public Awesome();
        Code:
           0: aload_0
           1: invokespecial #43                 // Method java/lang/Object."<init>":()V
           4: return
    }
    

    The first foo method with with Seq<Foo> argument corresponds to the Scala varargs method in Awesome. The second foo method with the Foo[] argument is the bridge method supplied by the Scala compiler.

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

Sidebar

Related Questions

I would like to implement a command line interface for a Java application. This
If I have an object implementing the Map interface in Java and I wish
I'm confused (new to java): When implementing the Runnable interface, one must override the
This is related to final interface in java . Among the discussion there was
Possible Duplicate: Java: What is the difference between implementing Comparable and Comparator? Difference between
I have created the following class implementing a ListSelectionListener interface. This class should listen
Possible Duplicate: Why there is no multiple inheritance in Java, but implementing multiple interfaces
I have working app1.ear , containing: JPA entity, MyObjectImpl , implementing interface MyObject from
I'm using the Observable class / Observer interface in Java to implement the observer
In Java, it is perfectly legal to define final arguments in interface methods and

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.