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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:04:11+00:00 2026-06-04T18:04:11+00:00

Class clazz = new Object(){}.getClass(); Why is this possible and what would it mean?

  • 0
Class clazz = new Object(){}.getClass();

Why is this possible and what would it mean? Could someone please remind me?

For example:

public class Testing {
    public static void main(String[] args) {
        Class clazz = new Object(){}.getClass();
        System.out.println(clazz);
    }
}

The result is: class Testing$1

  • 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-04T18:04:12+00:00Added an answer on June 4, 2026 at 6:04 pm

    It creates an anonymous inner class subclassing Object. The main use I’ve seen with an empty body is in Guice, for TypeLiteral, where it’s used to capture generic type arguments:

    key = new TypeLiteral<List<String>>() {};
    

    This is useful because type erasure doesn’t apply to the superclass here, so Guice is able to get the List<String> part out, which can’t be expressed as a normal class literal.

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

Sidebar

Related Questions

Why doesn't this code compile? public boolean isOf(Class clazz, Object obj){ if(obj instanceof clazz){
From time to time I see something like this: class Clazz { private int
I have the following methods: public <T> T fromJson( Reader jsonData, Class<T> clazz )
class A{ public A(){ System.out.println(in A); } } public class SampleClass{ public static void
Class A { string name; IList<A> minorList = new List<A>(); } IList<A> majorList =
class A { String s4 = abc; static public void main(String[]args ) { String
class A(object): _all = set() def __new__(cls): obj = super(A,cls).__new__(cls) cls._all.add(obj) return obj class
This code: println(new XStream.toXML(List(1,2,3))) produces this XML: <scala.coloncolon serialization=custom> <unserializable-parents/> <scala.coloncolon> <int>1</int> <int>2</int> <int>3</int>
I have a class that has a method as follows :- public void setCurrencyCode(List<String>
The following code does not compile: public class GenericsTest { public static void main(String[]

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.