(注意:Double只是一个例子)
初始化Double时,它需要Double或double作为值:
Double a = 0; //does not compile
Run Code Online (Sandbox Code Playgroud)
除非你加倍,否则追加'd'
Double b = (double)0; //compiles
Double c = 0d; //compiles
Run Code Online (Sandbox Code Playgroud)
当它变得令人困惑的是...
这个编译,虽然它的值变为0(int)
Double d = true ? 0 : 0d; //compiles, but always 0 (eclipse 'complains' on 0d calling it *Dead code*. So it knows it will return 0
Run Code Online (Sandbox Code Playgroud)
就像这样
Double e = false ? 0 : 0d; //compiles, always 0d
Run Code Online (Sandbox Code Playgroud)
但这些不编译:
Double f = false ? 0 : 0; //cannot convert from int to Double
Double g = true …Run Code Online (Sandbox Code Playgroud) 我正在用Herbert Schildt的书来学习Java:Java初学者指南.在那本书中出现了这段代码:
// A promotion surprise!
class PromDemo{
public static void main(String args[]){
byte b;
int i;
b = 10;
i = b * b; // OK, no cast needed
b = 10;
b = (byte) (b * b); // cast needed!!
System.out.println("i and b: " + i + " " + b);
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我必须在行中使用(byte):
b = (byte) (b * b); // cast needed!!
Run Code Online (Sandbox Code Playgroud)
b被定义为一个字节,b*b的结果是100,这是一个字节的正确值(-128 ... 127).
谢谢.
我最近有一个SNAFU导致我的集群最终出现裂脑(尽管有许多控制措施)导致碎片基本上被破坏.我已经让所有节点恢复正常,识别正确的主人等等,但是群集仍然是红色的,这是正确的; 有一些没有家的碎片.
在使用我的RubberBand脚本之后,我能够使用VisualJSON来查找像以下那样没有节点的分片:
{
"index": "logstash-2013.12.27",
"node": null,
"primary": false,
"relocating_node": null,
"shard": 4,
"state": "UNASSIGNED"
},
Run Code Online (Sandbox Code Playgroud)
我想删除它们,但我似乎无法找到删除分片的API调用,只删除整个索引或使用查询.提前致谢!
public class ProjectIdInitializer {
public static void setProjectId(String projectId) {
//load spring context which i want to escape in my test
}
}
public class MyService {
public Response create(){
...
ProjectIdInitializer.setProjectId("Test");
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest({ProjectIdInitializer.class})
public class MyServiceTest{
@InjectMocks
private MyService myServiceMock ;
public void testCreate() {
PowerMockito.mockStatic(ProjectIdInitializer.class);
PowerMockito.doNothing().when(ProjectIdInitializer.class, "setProjectId", Mockito.any(String.class));
// Does not work,still tries to load spring context
Response response=myServiceMock .create();
}
Run Code Online (Sandbox Code Playgroud)
如果从myservice调用ProjectIdInitializer.setProjectId(),我如何确保没有任何反应?
嗨,我有以下方法:
protected boolean shouldCheckLimit() {
if (startDate == null || endDate == null) {
return true;
}
final Long currentTime = System.currentTimeMillis();
if (startDate <= currentTime && currentTime < endDate) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
问题是findBugs发现了以下问题:
Possible null pointer dereference of TimeIntervalLimit.startDate in com.bet.blues.limit.TimeIntervalLimit.shouldCheckLimit() [Scary(8), Normal
Run Code Online (Sandbox Code Playgroud)
我必须提到startDate和endDate是Long变量.我尝试在条件中添加null的检查,我也尝试使用longValue()方法,但没有结果.你知道如何解决这个问题吗?可能是fndBugs方面的错误?
我在多台服务器上运行ElasticSearch.所有服务器都相同,都有2个磁盘:一个SSD和一个HDD.不用说,SSD更快但更小.
我知道你可以通过添加路径来在ES中设置多个数据目录elasticsearch.yml.但是,默认情况下(根据我的发现),ES会根据可用磁盘空间的百分比自动选择要采用的数据目录.
有些索引对我来说比其他索引更重要,比较新的(那些被大量查询的索引)需要在SSD上,而那些将被查询的索引可以在硬盘上.
如果可能的话,我需要做什么才能完成这项工作?
添加索引到路径?
我似乎无法从静态方法调用AsyncTask.它说"不能从静态上下文中引用".重要的是这个方法是静态的,我需要像我的其他一些过程那样.
有没有办法从方法中调用AsyncTask?
public static void UpdateResults(String requestSearch){
new GetSearchResults(requestSearch).execute(); //shows an error
}
class GetSearchResults extends AsyncTask<Void, Void, Void> {
String requestSearch;
GetSearchResults(String searchtext){
this.requestSearch = searchtext;
}
@Override
protected Void doInBackground(Void... params) {
//functions continuing
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:Anands解决方案工作,但它一旦到达方法就抛出此异常:
FATAL EXCEPTION: AsyncTask #1
Process: com.eproject.eproject.emobile, PID: 26831
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at com.eproject.eproject.emobile.SearchTabs.SearchPeopleTab$GetSearchResults.doInBackground(SearchPeopleTab.java:78)
at com.eproject.eproject.emobile.SearchTabs.SearchPeopleTab$GetSearchResults.doInBackground(SearchPeopleTab.java:63)
Run Code Online (Sandbox Code Playgroud)
显示空指针的第78行指向这行代码:
SharedPreferences accPref …Run Code Online (Sandbox Code Playgroud) java android static-methods android-asynctask android-activity
我正在学习mongoDB.我有一个看起来像这样的集合:
{
"_id" : ObjectId("558cf353209c021b5a2fcbe5"),
"term" : "gamma red eye tennis dampener",
"year" : "2015",
"month" : "05",
"day" : "29",
"hour" : "09",
"dayofyear" : "176",
"weekofyear" : "26",
"productcount" : "1",
"count" : "1"
}
{
"_id" : ObjectId("578cf353209c021b5a2fcbe5"),
"term" : "tennis dampener",
"year" : "2015",
"month" : "05",
"day" : "29",
"hour" : "09",
"dayofyear" : "176",
"weekofyear" : "26",
"productcount" : "1",
"count" : "7"
}
{
"_id" : ObjectId("568cf353209c021b5a2fcbe5"),
"term" : "gamma ",
"year" : …Run Code Online (Sandbox Code Playgroud) 我想使用分隔符","提取文件中的第一列,并将其保存到新文件中.输出生成此异常:
Exception in thread "main" java.lang.NullPointerException
at Extract.main(Extract.java:26)
Run Code Online (Sandbox Code Playgroud)
这是我使用的代码,但我不确定它是否正确:
public class Extract {
public Extract(){
}
public static void main(String[] args) {
BufferedReader in = null;
try {
BufferedWriter out = new BufferedWriter(new FileWriter("/home/omar/Téléchargements/nursery.tmp"));
in = new BufferedReader(new FileReader("pima.txt"));
String read = null;
while ((read = in.readLine()) != null) {
read = in.readLine();
String[] splited = read.split(",");
if (splited.length > 0)
{
out.append(splited[0].toString());
out.newLine();
}
}
} catch (IOException e) {
System.out.println("There was a problem: " + e);
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 我想添加两个数字.我从文本框中的按钮获取值.我还成功地将字符串拆分为子字符串,并将这些子字符串的值存储在变量中.但我无法将字符串类型转换为整数类型.这导致连接不是附加的.注意:我正在使用MVC来执行此任务.在模型中value1和value2是模型中的字符串类型这是我的代码片段:
if (button == "1"){
if (model.textBox == "" || model.textBox == null || model.textBox.ToLower().Contains("please enter value")){
model.textBox = "1";
} else {
model.textBox += "1";
}
}
if (button == "2") {
if (model.textBox == "" && model.textBox == null) {
model.textBox = "2";
} else {
model.textBox += "2";
}
if (button == "+") {
if (model.textBox == "" && model.textBox == null){
model.errormsg = "Please enter a number ";
} else {
model.textBox += "+";
}
if …Run Code Online (Sandbox Code Playgroud)