我编写了下面的代码来测试Java中的类和对象的概念.
public class ShowBike {
private class Bicycle {
public int gear = 0;
public Bicycle(int v) {
gear = v;
}
}
public static void main() {
Bicycle bike = new Bicycle(5);
System.out.println(bike.gear);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这会在编译过程中给出以下错误?
ShowBike.java:12: non-static variable this cannot be referenced from a static context
Bicycle bike = new Bicycle(5);
^
Run Code Online (Sandbox Code Playgroud) 我有一个关于Block的问题,这两个代码是否相同?
代码1
File::open('yozloy.txt','w') do |f|
f << 'Some contains'
end
Run Code Online (Sandbox Code Playgroud)
代码2
newFile = File::open('yozloy.txt','w')
newFile << 'Some contains'
Run Code Online (Sandbox Code Playgroud) #include<stdio.h>
int main(void){
int *ptr,a,b;
a = ptr;
b = ptr + 1;
printf("the vale of a,b is %x and %x respectively",a,b);
int c,d;
c = 0xff;
d = c + 1;
printf("the value of c d are %x and %x respectively",c,d);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出值是
the vale of a,b is 57550c90 and 57550c94 respectively
the value of c d are ff and 100 respectively%
Run Code Online (Sandbox Code Playgroud)
事实证明,ptr + 1实际上是这样的?
我刚发现<stdlib.h>和<stdio.h>标题位于/usr/includeUbuntu服务器的文件夹中,但我找不到sys/types.h.
我开始怀疑编译器实际上不会在/usr/include文件夹中使用头文件.
这是真的,文件位于何处?
我正在学习瘦服务器,现在我可以thin start用来启动服务器,但端口是3000,我应该在浏览器中输入localhost:3000来获取网页.
我想像其他网站一样取消3000端口.所以我设置使用命令thin -p 80 start来使用默认的http端口.但我得到了这个错误:
root@makserver:~/apps/videosite# thin --port 80 start
>> Using rack adapter
>> Thin web server (v1.2.7 codename No Hup)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:80, CTRL+C to stop
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_tcp_server': no acceptor (RuntimeError)
from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_server'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/tcp_server.rb:16:in `connect'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/base.rb:49:in `block in start'
from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/base.rb:57:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/server.rb:156:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/controllers/controller.rb:80:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:177:in `run_command'
from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:143:in `run!' …Run Code Online (Sandbox Code Playgroud) 在这个问题中,它指出,有可能有类似的东西:
message.myMessage = This message is for {0} in {1}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将参数传递给它
MESSAGES.getString("message.myMessage", "foor", "bar")
Run Code Online (Sandbox Code Playgroud)
但不幸的是getString无法知道拿其他参数有什么想法吗?
可能重复:
如何获取JavaScript对象的类?
在Ruby中,我可以这样做来检查实例的类:
'this is an string'.class
=>String
Run Code Online (Sandbox Code Playgroud)
在js中有类似的东西吗?
Time.new.month返回10月之前任何月份的单个数字表示(例如6月6),但我想要一个2位数格式(即6我想要的而不是06).
我写了以下解决方案,我要求看一些其他/更好的解决方案.
s = 6.to_s; s[1]=s[0]; s[0] = '0'; s #=> '06'
Run Code Online (Sandbox Code Playgroud) 我正在使用Ubuntu Server 10 lucid,ruby 1.9.2-p0.在irb中,左箭头显示^[[D.任何的想法?