免责声明:我对Java Generics没有丰富的经验,但是我和我的同事们花了一个小时试图破解一个结构如下的界面:
interface HasAttributes<A extends HasAttributes<A, B>,
B extends HasAttributesType<B>> extends Identification<B> {
Run Code Online (Sandbox Code Playgroud)
当接口泛型采用本身的类型参数时,它到底意味着什么?这是做什么的?
我刚开始学习scala.在尝试实现递归函数时,我在eclipse中收到错误"非法启动简单表达式":
def foo(total: Int, nums: List[Int]):
if(total % nums.sorted.head != 0)
0
else
recur(total, nums.sorted.reverse, 0)
def recur(total: Int, nums: List[Int], index: Int): Int =
var sum = 0 // ***** This line complained "illegal start of simple expression"
// ... other codes unrelated to the question. A return value is included.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我在(递归)函数中定义变量我做错了什么?我在网上进行了搜索,但无法解释这个错误.
在惯用JavaScript中,让函数接受"选项对象"作为最后一个参数是很常见的.这是您通常放置所有选项/很少使用的参数的地方,例如
jQuery.ajax({
url: "http://www.example.com/foo",
success: function() {
..
}
})
Run Code Online (Sandbox Code Playgroud)
Scala.JS的当前文档使用Scala特征来推荐表示选项对象,但是当您必须创建选项时会导致问题,因为您无法将匿名类传递给JavaScript代码.
如何从Scala代码创建这样的选项对象?
所以问题很简单:
我DatePicker在我的应用程序中集成了一个.不是作为一个DialogDatePickerView组件(更确切地说是一个View内部Fragment动态显示并从FrameLayout我的主FragmentActiviy布局中包含的内容中删除).
现在我的问题是这个DataPicker看起来像这样:

而不是这样的:

即使我定位较高的API,我也尝试将我的Min SDK设置为16或17,但它也没有任何帮助.
有人知道为什么会这样吗?以及如何显示数据选择器的新外观?最好是在旧版本的Android上?
任何帮助,将不胜感激.
谢谢.
编辑:代码:
DataPickerFragment xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="6.5dp"
android:paddingTop="6dp"
android:paddingRight="8.5dp"
android:paddingBottom="8.5dp"
android:background="@drawable/date_picker_background">
<DatePicker
android:id="@+id/datePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:paddingBottom="40dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/bCancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1.0"
android:onClick="buttonCanceDatePickerOnclick"
android:text="@string/cancel" />
<Button
android:id="@+id/bSave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1.0"
android:onClick="buttonSaveDatePickerOnclick"
android:text="@string/save" />
</LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
DataPickerFramgnet类:
public class DatePickerFragment extends Fragment {
private Button bSave, bCancel;
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用该ip2country表来显示我网站上用户的国家标志.
我想出的最简单的事情是编写一个SQL语句,该语句从会话表中获取用户并查询它们各自的IP是否在某个范围内以确定其国家/标志.
这很简单但也很危险,因为当有300个在线用户显示并从会话表中获取它们时,查询他们的国家/地区以显示标志,肯定会有大量内存使用.
现在我尝试在一个查询中执行此操作:
SELECT
s.session_ip,
ipc.*
FROM
session AS s
LEFT JOIN ip2country AS ipc
ON ipc.ip_lo <= s.session_ip AND ipc.ip_hi >= s.session_ip
WHERE
s.session_time > '".( time() - 60) )."'
Run Code Online (Sandbox Code Playgroud)
现在很清楚,上面的查询是错误的,因为ip2country表中保存的IP 是一个整数,例如1000013824,存储在会话表中的IP是IP的字符串表示,例如193.169.0.0
我知道如何用PHP将IP转换为long ip2long(),但MySQL中是否有任何等效的方法,所以我不需要做两个查询?
在阅读 Java 中 java.util.Random 类的文档时,我偶然发现了next方法内部的一些我无法理解的东西。
protected int next(int bits) {
long oldseed, nextseed;
AtomicLong seed = this.seed;
do {
oldseed = seed.get();
nextseed = (oldseed * multiplier + addend) & mask;
} while (!seed.compareAndSet(oldseed, nextseed));
return (int)(nextseed >>> (48 - bits));
}
Run Code Online (Sandbox Code Playgroud)
我注意到了 的使用!seed.compareAndSet(oldseed, nextseed),我试图了解它的用途。解释是什么?
我使用以下方法创建了一个ScalaJS项目:
http://www.scala-js.org/doc/tutorial.html
阅读http://www.scala-js.org/doc/faq.html上的文档,似乎没有描述创建和调用JavaScript函数?
如何创建JavaScript函数并调用它?
我将手动将d3添加到index.html的head元素:
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
但是如何使用ScalaJS创建以下代码?
$(document).ready(function () {
var svgContainer = d3.select("body").append("svg")
.attr("width", 1200)
.attr("height", 1200)
.attr("text-align", "center");
testFunction(svgContainer);
});
<script>
function testFunction(svgContainer) {
alert(svgContainer)
}
</script>
Run Code Online (Sandbox Code Playgroud)
整个index.html:
<!DOCTYPE html>
<html>
<head>
<title>Example Scala.js application</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Example Scala.js application - full-optimized version</h1>
<p>After having compiled and full-optimized properly the code for the application
(using `sbt fullOptJS`), you should see "It works" herebelow.
See README.md for detailed explanations.</p> …Run Code Online (Sandbox Code Playgroud) 我可以通过以下语法访问实例字段:student.address.city
public class Student {
private Address address;
//getters&setters
}
public class Address {
private String town;
private String street;
private String city;
//getters&setters
}
Run Code Online (Sandbox Code Playgroud)
我认为可以通过反射以某种方式完成。基本上我需要这样的东西:
String city = getPropertyValue("student.address.city", student);
Run Code Online (Sandbox Code Playgroud)
像在js中一样,我们可以访问对象属性。
java ×3
scala ×2
scala.js ×2
android ×1
atomic ×1
d3.js ×1
datepicker ×1
generics ×1
javascript ×1
mysql ×1
php ×1
random ×1
reflection ×1
syntax ×1