Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid member vs. property name collisions in JRubyJar #215

Merged
merged 1 commit into from
Sep 10, 2015

Conversation

rtyler
Copy link
Member

@rtyler rtyler commented Sep 10, 2015

When using a member variable that is named the same as a property, the behavior
from subclassing can be very confusing

Take the following example:

    class Parent {
        protected String configuration = "foo"

        String getConfiguration() {
            return configuration
        }

        void doSomething() {
            logger.info("Parent using ${configuration}")
        }
    }

    class Child {
        String getConfiguration() {
            return 'hello'
        }

        void doSomething() {
            logger.info("Child using ${configuration}")
            super.doSomething()
        }
    }

Invoking childInstance.doSomething() will output:

Child using hello
Parent using foo

This can be remedied (pointed out by @ysb33r) by calling this.@configuration
which will force a property lookup in Groovy. I personally find it less
error-prone to keep member names ddifferent from the proprty names which expose
them as a non-protected/private API.

Fixes jruby-gradle/jruby-gradle-storm-plugin#21

@ysb33r
Copy link
Contributor

ysb33r commented Sep 10, 2015

Looks good to me

…sing easier

When using a member variable that is named the same as a property, the behavior
from subclassing can be very confusing

Take the following example:

    class Parent {
        protected String configuration = "foo"

        String getConfiguration() {
            return configuration
        }

        void doSomething() {
            logger.info("Parent using ${configuration}")
        }
    }

    class Child {
        String getConfiguration() {
            return 'hello'
        }

        void doSomething() {
            logger.info("Child using ${configuration}")
            super.doSomething()
        }
    }

Invoking childInstance.doSomething() will output:

    Child using hello
    Parent using foo

This can be remedied (pointed out by @ysb33r) by calling `this.@configuration`
which will force a property lookup in Groovy. I personally find it less
error-prone to keep member names ddifferent from the proprty names which expose
them as a non-protected/private API.

Fixes jruby-gradle/jruby-gradle-storm-plugin#21
@rtyler
Copy link
Member Author

rtyler commented Sep 10, 2015

The test failures were due to a copy paste error, accidentailly deleted the mainClass property when shuffling things around prior to committing. Hooray CI!

rtyler pushed a commit that referenced this pull request Sep 10, 2015
Avoid member vs. property name collisions in JRubyJar
@rtyler rtyler merged commit 8404576 into jruby-gradle:master Sep 10, 2015
@rtyler rtyler deleted the private-property branch September 10, 2015 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants