为什么UTF-16字符串中的2个字符在内存中只占用6个字节,而1个字符的UTF-16字符串占用4个字节?
这是java中的SSCCE来演示这种行为:
public class UTF16Test{
public static void main(String[] args) throws Exception {
System.out.println("A".getBytes("UTF-16").length);
System.out.println("AB".getBytes("UTF-16").length);
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
4
6
Run Code Online (Sandbox Code Playgroud) 这是微不足道的,但不幸的是我不了解JSF中的"幕后"流程.所以,我也对相关文章的链接感兴趣.
问题:我有一个用户对象列表.我将此列表表示为dataTable.
<h:dataTable var="user" value="#{userService.allUsers}">
<h:column>
<f:facet name="header">
<h:outputText value="Login"/>
</f:facet>
<h:outputText value="#{user.login}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Birthdate"/>
</f:facet>
<h:outputText value="#{user.birthDate}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{user.name}"/>
</h:column>
<h:column>
<!--This form with button is not a real code, just my suggestion how these things should be done-->
<h:form>
<h:commandButton action="openEditForm" value="Edit"/>
</h:form>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
现在我想将commandButton"Edit"添加到每个表行.单击此按钮应该打开一些带有可编辑字段的表单,我们可以在其中更改当前值.
<!--It's not a real code, just my suggestion how these things should be done-->
<h:form>
<h:inputText value="#{user.login}"/>
<h:inputText value="#{user.birthDate}"/>
<h:inputText value="#{user.name}"/> …Run Code Online (Sandbox Code Playgroud) 我的意思是:
public class SomeBackingBean {
protected String someString;
public void setSomeString (String str) {
this.someString = str;
}
public String getSomeString {
return someString;
}
}
Run Code Online (Sandbox Code Playgroud)
这只是一般答案的一般情况.
现在第二个例子:
public abstract class AbstractBean<T extends EntityInterface> {
protected T entity;
public void setEntity (T t) {
this.entity = t;
}
public void getEntity () {
return entity;
}
protected ReturnType calculateSomethingCommon () {
//use entity (knowing that it implements EntityInterface)
//to implement some common for all subclasses logic
}
}
public class …Run Code Online (Sandbox Code Playgroud) 所以这是我的代码:
public MyClass (int y) {
super(y,x,x);
//some code
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,在这种情况下,我想生成一个'x'并发送到超级构造函数.但是,对超构造函数的调用必须是此构造函数中的第一行.当然我可以这样做:
int x;
{
x = generateX();
}
Run Code Online (Sandbox Code Playgroud)
但这感觉很难看,然后无论我使用什么构造函数,代码都会运行,感觉不太好.现在我考虑将我的整个对象封装在另一个只计算x的对象中然后启动这个对象.这是最好的方法吗?
简单的例子:我们有字符串"Some sample string Of Text".我想过滤掉所有停用词(即"some"和"of"),但我不想改变应该保留的其他词的字母大小写.
如果信件不重要我会这样做:
str.toLowerCase().replaceAll ("a|the|of|some|any", "");
Run Code Online (Sandbox Code Playgroud)
在java中是否存在带有正则表达式的"忽略大小写"解决方案?
我不知道haskell语法,但我知道一些FP概念(如代数数据类型,模式匹配,高阶函数等).
有人可以解释一下,这段代码意味着什么:
data Tree ? = Leaf ? | Fork ? (Tree ?) (Tree ?)
rotateR tree = case tree of
Fork q (Fork p a b) c -> Fork p a (Fork q b c)
Run Code Online (Sandbox Code Playgroud)
据我所知,第一行就像Tree-type声明(但我完全不明白).第二行包括模式匹配(我不明白为什么我们需要在这里使用模式匹配).第三行为非haskell开发人员做了一些绝对不可读的事情.我已经找到了Fork的定义,fork (f,g) x = (f x, g x)但我不能再继续前进了.
我想知道使用如下构造是否可靠:
private static final Map<String, String> engMessages;
private static final Map<String, String> rusMessages;
static {
engMessages = new HashMap<String, String> () {{
put ("msgname", "value");
}};
rusMessages = new HashMap<String, String> () {{
put ("msgname", "????????");
}};
}
private static Map<String, String> msgSource;
static {
msgSource = engMessages;
}
public static String msg (String msgName) {
return msgSource.get (msgName);
}
Run Code Online (Sandbox Code Playgroud)
有可能我会得到NullPointerException因为msgSource初始化块之前会执行初始化块engMessages吗?
(关于为什么我不在msgSource初始化结束时进行初始化.块:只是味道问题;如果描述的结构不可靠,我会这样做)
我刚刚设置了一个代理,并通过该代理运行我的所有请求.
我调查了几个不同的应用程序:它们传递登录和密码对raw,即我可以从POST请求参数中获取它们.
如何实现它以使其更安全?(我还没有调查过gmail和facebook,但我认为他们没有这个问题.否则,任何网吧都可以收集其客户的所有账户,例如).
PS我调查了用JSP和GWT编写的网站.
Statement从版本1.6开始,在接口中声明了另外三种方法.
据我了解,这打破了java最大的优势之一 - 向后兼容性.从jdk 1.5过渡到jdk 1.6后,我的项目不再编译,我必须更改代码.
什么是添加这三种方法(的推理isPoolable,setPoolable,isClosed在这样一个糟糕的方式)?
java ×7
jsf ×2
binary-tree ×1
charts ×1
components ×1
constructor ×1
conventions ×1
data-binding ×1
gwt ×1
haskell ×1
javabeans ×1
jls ×1
jsp ×1
oop ×1
regex ×1
security ×1
string ×1
syntax ×1
utf-16 ×1