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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:38:19+00:00 2026-06-07T21:38:19+00:00

According to http://groovy.codehaus.org/Things+you+can+do+but+better+leave+undone Accessing an object’s type like a property Using .class instead of

  • 0

According to http://groovy.codehaus.org/Things+you+can+do+but+better+leave+undone

  1. Accessing an object’s type like a property

Using .class instead of .getClass() is ok – as long as you know
exactly what kind of object you have. But then you don’t need that at
all. Otherwise, you run in the risk of getting null or something else,
but not the class of the object.

a = [:] println a.class.simpleName // NullPointerException, because
a.class is null.

Can someone explain why this is? Why does .class return something different than getClass()

  • 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-07T21:38:23+00:00Added an answer on June 7, 2026 at 9:38 pm

    Because when a is a map, a.class is the same in Groovy as a.get( "class" ). As you can see in the example in the docs, this will return null. That’s why the rule trends to be to use getClass unless you’re absolutely sure the variable won’t be a map

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

Sidebar

Related Questions

I am new to python and graphics but have programmed before. According to http://en.wikipedia.org/wiki/Transformation_matrix#Rotation
According to http://www.w3.org/TR/IndexedDB/#widl-IDBCursor-continue , the IDBCursor object has methods named continue and delete. Aren't
According to http://en.wikipedia.org/wiki/Fold_(higher-order_function ), a right fold can operate on infinite lists if the
According to http://msdn.microsoft.com/en-us/library/ms810291.aspx , you can't change the ReadOnly attribute of an Expression based
According to http://lipas.uwasa.fi/~ts/info/proctips.html#orrules , you can make basic or rules in .procmailrc with something
According to http://www.regular-expressions.info , You can consider \X the Unicode version of the dot
According to http://en.wikipedia.org/wiki/Producer-consumer_problem I want to simulate P/C problem using semaphore. I am getting
I'm struggling with a strange issue. According to http://github.com/sinatra/sinatra (secion Filters) a response object
I have used emacs for erlang programming. According to http://emacswiki.org/emacs/CompileCommand , I have configure
According to http://www.rebol.com/docs/core23/rebolcore-15.html You can use change/part to parse and replace but that doesn't

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.