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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:36:58+00:00 2026-05-25T20:36:58+00:00

I have a Java object OldFashioned that extends Java 1.4 List : [Java] class

  • 0

I have a Java object OldFashioned that extends Java 1.4 List:

[Java] 
class OldFashioned extends List { ... }

That is, OldFashioned doesn’t take any type parameters. I need to add SomeObject to it. In Java there’s no problem, since it treats List 1.4 as List<Object> 1.5 and allows to add any subclasses of Object to the collection. But Scala doesn’t. So next code doesn’t work:

[Scala]
val oldFashioned = new OldFashioned()
oldFashioned.add(new SomeObject)       // found: SomeObject; required: E

That is, Scala compiler requires to pass type parameters to OldFashioned that actually doesn’t take them:

[Scala]
var oldFashioned: OldFashioned[SomeObject] = null    // OldFashioned does not take type parameters

How can I overcome it and add SomeObject to OldFashined?

  • 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-25T20:36:59+00:00Added an answer on May 25, 2026 at 8:36 pm

    Ok, I can’t believe one of my earlier question finds a usage here (you should go upvote agilesteel’s answer)

    def add(oldFashioned: OldFashioned, any: Any): Boolean = oldFashioned match {
      case l: java.util.List[a] => l.add(any.asInstanceOf[a])
    }
    
    val oldFashioned = new OldFashioned
    // oldFashioned: OldFashioned = []
    
    add(oldFashioned, "test")
    // res0: Boolean = true
    add(oldFashioned, 1)
    // res1: Boolean = true
    add(oldFashioned, new Object)
    // res2: Boolean = true
    
    oldFashioned
    // res3: OldFashioned = [test, 1, java.lang.Object@1db8f8e]
    

    Edit: I guess as long as I’m going to cast:

    oldFashioned.asInstanceOf[java.util.List[SomeObject]].add(new SomeObject)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have the Java code: Object arr = Array.newInstance(Array.class, 5); Would that run?
I have a list of java object that have 4 members. int id; String
I have a java object that implements Runnable. here is the code. public class
I have a java.sql.ResultSet object that I need to update. However the result set
I have a list of java object that have 4 members. int id; String
I have a Java Properties object that I load from an in-memory String ,
I have a java.sql.ResultSet object containg data from a query that was run. How
If you have a java.io.InputStream object, how should you process that object and produce
I have a MATLAB class which contains a reference to a java object classdef
On a JSTL/JSP page, I have a java.util.Date object from my application. I need

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.