0

我似乎无法从 JRuby 中调用任何 Java 的字符串方法。不过,同样的语法风格也适用于 Math 类。我究竟做错了什么?

#! /usr/bin/env jruby

require 'rubygems'
require 'java'

puts java.lang.Math::max(1000,200)
puts java.lang.Math::PI

# this doesn't work 
puts java.lang.String::toUpperCase("we, the people")

# this doesn't work either 
JString = java.lang.String
puts JString.toUpperCase('We, the people')

#toUpperCase exists though, see below
puts java.lang.String.java_class.declarSed_instance_methods
4

1 回答 1

3

我认为这就是你想要做的:

java.lang.String.new("we, the people").toUpperCase

正如@Jesper 所提到的, toUpperCase 是 String 类的实例方法。将其用作静态方法将不起作用。

另请注意,返回的类是原生 Ruby 类型。

于 2013-02-10T14:48:18.447 回答