具体来说,我正在尝试这段代码:
package hello;
public class Hello {
Clock clock = new Clock();
public static void main(String args[]) {
clock.sayTime();
}
}
Run Code Online (Sandbox Code Playgroud)
但它给出了错误
无法访问静态方法main中的非静态字段
所以我把声明改为clock:
static Clock clock = new Clock();
Run Code Online (Sandbox Code Playgroud)
它奏效了.在声明之前放置该关键字是什么意思?对于该对象可以做什么,它究竟会做什么和/或限制什么?
问题如下:
我有以下XML片段:
<time format="minutes">11:60</time>
Run Code Online (Sandbox Code Playgroud)
问题是我无法同时添加属性和限制.属性格式只能包含分钟,小时和秒.时间有限制模式\d{2}:\d{2}
<xs:element name="time" type="timeType"/>
...
<xs:simpleType name="formatType">
<xs:restriction base="xs:string">
<xs:enumeration value="minutes"/>
<xs:enumeration value="hours"/>
<xs:enumeration value="seconds"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="timeType">
<xs:attribute name="format">
<xs:simpleType>
<xs:restriction base="formatType"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
如果我创建一个复杂类型的timeType,我可以添加一个属性,但不能添加限制,如果我创建一个简单类型,我可以添加限制但不添加属性.有没有办法解决这个问题.这不是一个非常奇怪的限制,或者是它?
我有类别列表.我需要排除2,3行的类别列表.我们可以通过使用Criteria和Restriction来实现休眠吗?
>>> class BOOL(bool):
... print "why?"
...
why?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
type 'bool' is not an acceptable base type
Run Code Online (Sandbox Code Playgroud)
我以为Python信任程序员.
我想限制所有API控制器的请求被重定向到JSON路径.我想使用重定向,因为URL也应根据响应而改变.
一种选择是使用a before_filter将请求重定向到相同的操作但强制JSON格式.这个例子还没有用!
# base_controller.rb
class Api::V1::BaseController < InheritedResources::Base
before_filter :force_response_format
respond_to :json
def force_response_format
redirect_to, params[:format] = :json
end
end
Run Code Online (Sandbox Code Playgroud)
另一种选择是限制路线设置中的格式.
# routes.rb
MyApp::Application.routes.draw do
namespace :api, defaults: { format: 'json' } do
namespace :v1 do
resources :posts
end
end
end
Run Code Online (Sandbox Code Playgroud)
我希望所有请求都以JSON请求结束:
http://localhost:3000/api/v1/posts
http://localhost:3000/api/v1/posts.html
http://localhost:3000/api/v1/posts.xml
http://localhost:3000/api/v1/posts.json
...
Run Code Online (Sandbox Code Playgroud)
你会推荐哪种策略?
浏览器对于并行XHR的数量(现在约为6)具有每主机限制.
此限制是否适用于多路复用HTTP/2连接?
我想限制SQL表中的列值.例如,列值只能是"car"或"bike"或"van".我的问题是你如何在SQL中实现这一点,并且在数据库方面这样做是一个好主意,或者我应该让应用程序限制输入.
我还打算将来添加或删除更多值,例如"truck"
我使用的数据库类型是SQLite和MySQl
我有一个名为Inconsistent accessibility的错误:
字段类型'world'比字段'frmSplashScreen'更难访问
在我的代码中有一个名为的公共分部类 frmSplashScreen
还有一个名为的公共课 world
导致错误的行是:
private world currentWorld;
Run Code Online (Sandbox Code Playgroud)
以上这一行是在课堂上 frmSplashScreen
是什么导致了这个问题?
当你有一个在object-instatiation时已知的变量时,应该使用readonly字段,之后不应该更改.
但是,不允许从子类的构造函数中分配只读字段.如果超类是抽象的,这甚至都不起作用.
有没有人有一个很好的解释为什么这不是一个好主意,或缺乏C#languange?
abstract class Super
{
protected readonly int Field;
}
class Sub : Super
{
public Sub()
{
this.Field = 5; //Not compileable
}
}
Run Code Online (Sandbox Code Playgroud)
PS:您当然可以通过在超类中的受保护构造函数中分配只读字段来获得相同的结果.
我想我已经搜索了很多关于这一点但仍然没有去.
将不胜感激任何帮助.
我试图限制具有空内容的元素的属性."color"应限制为仅保持3位数或minLength = 3且maxLength = 3.它不应该有任何内容.
<?xml version="1.0" encoding="utf-8"?>
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<product id="" name="">
<article id="1001">
<umbrella color="100"/>
<umbrella color="101"/>
</article>
<article id="1002">
<umbrella color="110"/>
</article>
</product>
</items>
Run Code Online (Sandbox Code Playgroud)
编辑:我知道如何对simpleType进行XSD限制.但我不知道如何将它与一个具有ComplexType的实体结合起来.
如果您能提供更详细(或完整)的解决方案,我会很高兴.
顺便说一句,"颜色"不限于xs:整数.它实际上是一个xs:string.