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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:41:16+00:00 2026-06-11T15:41:16+00:00

Using scala-2.10.0-M7, consider the following Scala program: import reflect.runtime.universe._ object ScalaApplication { def main(args:

  • 0

Using scala-2.10.0-M7, consider the following Scala program:

import reflect.runtime.universe._

object ScalaApplication {
  def main(args: Array[String]) {
    val list = List(42)
    printValueAndType(list)
    printValueAndType(list(0))

  }

  def printValueAndType (thing: Any) {
    println("Value: " + thing)
    println(reflect.runtime.currentMirror.reflect(thing).symbol.toType match {case x:TypeRef => "Type: " + x.args});
  }

}

It gives the following output:

$ scala ScalaApplication.scala 
Value: List(42)
Type: List()
Value: 42
Type: List()

Why is the type of list the same as the type of list(0)?

I would have expected something similar to the behaviour of the following Java program:

public class JavaApplication {
    public static void main(String[] args) {

        Integer[] list = new Integer[]{42};

        printValueAndType(list);
        printValueAndType(list[0]);

    }

    public static void printValueAndType(Object o) {
        System.out.println("Value: " + o.toString());
        System.out.println("Type: " + o.getClass().getSimpleName());
    }

}

Which gives the result:

$ java JavaApplication
Value: [Ljava.lang.Integer;@16675039
Type: Integer[]
Value: 42
Type: Integer

In summary:
Why is the type for both the list and the list element reported as List()?

  • 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-11T15:41:18+00:00Added an answer on June 11, 2026 at 3:41 pm

    x.args gives you the type arguments of the type. Since they aren’t available at runtime, you get an empty list for the first case and since Int does not have any type arguments, you get an empty list there as well. You can just print out the symbol directly.

    println(reflect.runtime.currentMirror.reflect(thing).symbol)
    

    This produces

    Value: List(42)
    class ::
    Value: 42
    class Integer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following test program (using scala 2.9.0.1) object test { def main(args:Array[String])
Consider the file bug.scala : package sandbox object Foo { implicit def stringToInt(s: String)
Consider the following sketch for using a loop to empty a queue in Scala:
I'm using Scala 2.8 and defining an Enumeration like this: object Stooges extends Enumeration
Consider the following simple DAG: 1->2->3->4 And a table, #bar, describing this (I'm using
Consider the following code, derived from the metascala project : object Units { case
Consider the following: scala> val a:java.lang.Boolean = true a: java.lang.Boolean = true scala> val
Possible Duplicate: Applying an argument list to curried function using foldLeft in Scala Consider:
I am using Scala combinatorial parser by extending scala.util.parsing.combinator.syntactical.StandardTokenParser . This class provides following
I am trying to solve the following codechef problem using scala. The statement of

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.