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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:21:31+00:00 2026-05-30T19:21:31+00:00

In Groovy everything is Object, even numbers assert 1.getClass() == Integer In Groovy you

  • 0

In Groovy everything is Object, even numbers

assert 1.getClass() == Integer

In Groovy you can override existing method in an existing class in runtime

Integer.metaClass.or = { right -> println "$delegate or $right" }

Now we can call or operator on any number using pipe (|)

1.or("hello") // prints: 1 or hello
1 | "hello" // prints: 1 or hello

So far so good. Now let’s try to or an Integer with an Integer

2.or(3) // nothing happens
2 | 3 // nothing happens

This leads us to my questions:

  • Why nothing happens?
  • Is this an optimization bug?
  • How to make it work for any type?
  • 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-30T19:21:33+00:00Added an answer on May 30, 2026 at 7:21 pm

    It’s probably choosing an already existing or method that takes an integer, rather than your more generic Object version.

    Does it work if you do:

    Integer.metaClass.or = { Integer right -> println "$delegate or $right" }
    

    Not at a computer at the moment though, so can’t validate this :-/

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

Sidebar

Related Questions

Groovy adds the execute method to String to make executing shells fairly easy; println
Groovy adds the isAllWhitespace() method to Strings, which is great, but there doesn't seem
I've developed a Wordpress theme locally and everything is groovy. On uploading to our
I'm using groovy gsql to query to Mysql database. Everything goes well on localhost
I like how Groovy makes all of your instance variables and class variables public
Groovy seems to be unable to compile a class where I've derived from a
Groovy has a nice operator for safe dereferencing, which helps to avoid NullPointerExceptions: variable?.method()
Using groovy, would you expect better performance in terms of speed and memory overhead
In Groovy, how do I grab a web page and remove HTML tags, etc.,
The Groovy Process Management page mentions that: Because some native platforms only provide limited

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.