引自http://sites.google.com/site/gson/gson-design-document:
为什么Gson中的大多数课程都被标记为最终?
虽然Gson通过提供可插拔序列化器和反序列化器提供了相当可扩展的架构,但Gson类并未专门设计为可扩展.提供非最终类将允许用户合法地扩展Gson类,然后期望该行为在所有后续修订中工作.我们选择通过将类标记为final来限制这样的用例,并等到出现良好的用例以允许扩展性.标记类final也有一个很小的好处,即为Java编译器和虚拟机提供额外的优化机会.
为什么会这样?[如果我猜测:JVM知道类是最终的,它不维护方法覆盖表?还有其他原因吗?]
性能有什么好处?
这是适用于频率实例化的类(POJO?)还是适用于持有静态方法(实用类)的类?
定义为final的方法在理论上也可以提高性能吗?
有什么影响吗?
谢谢你,马克西姆.
如何使HTTPClient使用自定义User-Agent标头?
以下代码提交空用户代理.我错过了什么?
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
public class TestHTTP {
public static void main(String[] args) throws ClientProtocolException, IOException {
HttpGet request = new HttpGet("http://tool.keepmeapi.com/echo");
HttpContext HTTP_CONTEXT = new BasicHttpContext();
HTTP_CONTEXT.setAttribute(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
request.setHeader("Referer", "http://www.google.com");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request, HTTP_CONTEXT);
if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 400) { …Run Code Online (Sandbox Code Playgroud) public class A {
public void f1(String str) {
System.out.println("A.f1(String)");
this.f1(1, str);
}
public void f1(int i, String str) {
System.out.println("A.f1(int, String)");
}
}
public class B extends A {
@Override
public void f1(String str) {
System.out.println("B.f1(String)");
super.f1(str);
}
@Override
public void f1(int i, String str) {
System.out.println("B.f1(int, String)");
super.f1(i, str);
}
}
public class Main {
public static void main(String[] args) {
B b = new B();
b.f1("Hello");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在寻求这段代码输出:
B.f1(String)
A.f1(String)
A.f1(int, String)
Run Code Online (Sandbox Code Playgroud)
但我得到了:
B.f1(String)
A.f1(String)
B.f1(int, …Run Code Online (Sandbox Code Playgroud) 让我们假设我有这样的样本数据:
| Name | ID | PARENT_ID |
-----------------------------
| a1 | 1 | null |
| b2 | 2 | null |
| c3 | 3 | null |
| a1.d4 | 4 | 1 |
| a1.e5 | 5 | 1 |
| a1.d4.f6 | 6 | 4 |
| a1.d4.g7 | 7 | 4 |
| a1.e5.h8 | 8 | 5 |
| a2.i9 | 9 | 2 |
| a2.i9.j10| 10 | 9 |
Run Code Online (Sandbox Code Playgroud)
我想从accountId = …
我的API允许库客户端传递日期:
method(java.util.Date date)
Run Code Online (Sandbox Code Playgroud)
与Joda-Time合作,从这一天开始,我想提取月份并迭代本月所有日子.
现在,传递的日期通常是新的Date() - 意味着当前的瞬间.我的问题实际上是将新的DateMidnight(jdkDate)实例设置为月初.
有人可以用Joda-Time演示这个用例吗?
我刚开始学习概率,我正在寻找可以在linux上工作的工具.
我找到了一些组合软件包http://rss.acs.unt.edu/Rdoc/library/Combinations/html/00Index.html但是当我尝试安装它们时,该过程失败并显示以下消息:
> install.packages("Combinations")
Installing package(s) into ‘/home/maxim/R/x86_64-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘Combinations’ is not available (for R version 2.13.1)
Run Code Online (Sandbox Code Playgroud) 我已阅读并发编程指南
在指南中,文本指出GCD调度队列定义了他们自己的@autoreleasepool池,并提到仍然建议在每个调度级别定义一个,但是对于NSOperation没有说什么,Apple提供的示例代码也没有显示@autoreleasepool结构.在NSOperation的背景下,模糊地提到@autoreleasepool的唯一地方是修订历史,
2012-07-17 - 删除了有关自动释放池使用操作的过时信息.
查看在线提供的示例代码,例如 http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues在基于NSOperations的对象的实现中使用@autoreleasepool,例如:
@implementation ImageDownloader
- (void)main {
@autoreleasepool {
...
}
}
@end
Run Code Online (Sandbox Code Playgroud)
nsoperation nsautoreleasepool ios automatic-ref-counting ios8
似乎mmap接口只支持readline().如果我尝试迭代对象,我会得到字符而不是完整的行.
什么是逐行读取mmap文件的"pythonic"方法?
import sys
import mmap
import os
if (len(sys.argv) > 1):
STAT_FILE=sys.argv[1]
print STAT_FILE
else:
print "Need to know <statistics file name path>"
sys.exit(1)
with open(STAT_FILE, "r") as f:
map = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
for line in map:
print line # RETURNS single characters instead of whole line
Run Code Online (Sandbox Code Playgroud) 试图安装Nokogiri我收到以下错误
Maxims-MacBook-Air:ScrapingTheApple maximveksler$ gem install nokogiri
Fetching: nokogiri-1.6.2.1.gem (100%)
Building native extensions. This could take a while...
Building nokogiri using packaged libraries.
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/maximveksler/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You …Run Code Online (Sandbox Code Playgroud) 我正在考虑使用匿名{}代码块在逻辑上区分同一方法调用中的"代码块" 的选项,这(理论上)应该提高代码的可读性.
我想知道以下哪两个代码段对你的眼睛更好?
另外,2个代码段是否编译为相同的字节码?换句话说,可以使用{}以任何方式伤害代码的性能吗?
public static String serviceMatch(HttpServletRequest servletRequest, RequestTypeEnum requestTypeEnum, ...censorsed..., RequestStatistics requestStatistics) {
Request request;
// We get the parser that fits the ...censorsed..., effectively transforming the HTTPReqeuest to application local "Request*" object
RequestParser parser = RequestParserFactory.getParser(...censorsed...);
// Populate basic parameters, the "heavy" data will be lazy loaded
request = parser.parse(servletRequest);
// Instead of polluting the parsers let's put it here... (unless we identify meaningful justifications for the other alternative of changing RequestParser.parse() …Run Code Online (Sandbox Code Playgroud) java ×5
performance ×2
coding-style ×1
combinations ×1
database ×1
date ×1
file ×1
final ×1
gem ×1
ios ×1
ios8 ×1
jodatime ×1
jvm ×1
mmap ×1
nokogiri ×1
nsoperation ×1
oop ×1
optimization ×1
oracle ×1
osx-yosemite ×1
overloading ×1
plsql ×1
python ×1
r ×1
sql ×1
text ×1
theory ×1
user-agent ×1