JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-5866

JRuby can't access nested Java class if the class is called 'id'

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: JRuby 1.6.2
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: Java Integration
    • Labels:
      None
    • Environment:
      Android 3.1, ruboto-core master
    • Number of attachments :
      0

      Description

      Hi!

      I need to access

      android.R.id.home
      
      or
      
      android.R::id.home
      

      This is a standard constant in Android. "id" is an inner class of android.R.

      I am able to access the class using

      JavaUtilities.get_proxy_class('android.R$id').home
      

      so I have an acceptable workaround, but JRUBY-4666 states I should be able to access the class without using JavaUtilities.

      Any way to do this?

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        The main problem here is that the class starts with a lower-case name; we don't currently map inner classes that are not capitalized.

        The easiest way to do this may be to import the class as a specific name, rather than trying to access it directly:

        ~/projects/jruby ➔ cat Blah.java
        public class Blah {
          public static class id {
            public static String hello() {
              return "hello";
            }
          }
        }
        
        ~/projects/jruby ➔ jruby -rjava -e 'import "Blah$id" do; "Blah_id"; end; p Blah_id.hello'
        "hello"
        

        I suppose we could improve the inner class mapping to support lower-case class names, but in general all such cases we've left to explicit imports, even for normal top-level classes.

        Show
        Charles Oliver Nutter added a comment - The main problem here is that the class starts with a lower-case name; we don't currently map inner classes that are not capitalized. The easiest way to do this may be to import the class as a specific name, rather than trying to access it directly: ~/projects/jruby ➔ cat Blah.java public class Blah { public static class id { public static String hello() { return "hello"; } } } ~/projects/jruby ➔ jruby -rjava -e 'import "Blah$id" do; "Blah_id"; end; p Blah_id.hello' "hello" I suppose we could improve the inner class mapping to support lower-case class names, but in general all such cases we've left to explicit imports, even for normal top-level classes.
        Hide
        Uwe Kubosch added a comment -

        Closing this since there are two acceptable ways to do this.

        Show
        Uwe Kubosch added a comment - Closing this since there are two acceptable ways to do this.

          People

          • Assignee:
            Unassigned
            Reporter:
            Uwe Kubosch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: