说我有一个List,我知道我永远不想添加null它.如果我向它添加null,则意味着我犯了一个错误.因此,每次我打电话,list.add(item)我都会打电话if (item == null) throw SomeException(); else list.add(item);.是否存在List为我这样做的现有类(可能在Apache Commons或其他内容中)?
类似的问题:帮助删除Java列表中的空引用?但我不想删除所有空值,我想确保它们从未被添加到第一位.
我即将在TortoiseSVN中做一个提交,涉及重新安排很多文件和目录.在"提交"窗口中,有几个文件的文本状态为"已删除"或"已添加",但其他文件状态为"已删除(+)"或"已添加(+)"的文件.(+)是什么意思?
(对于一个加号来说谷歌很难,而且"加号"这个词在蓝色叠加图标上显示了大量的点击,意思是"添加")
这句话可以在XUL的Mozilla文档中看到.在这种情况下,铬这个词意味着什么?
一个非常简单的代码来说明差异.
var x = [0, 3, 1, 2];
console.debug('debug', x);
console.log('log', x);
// above display the same result
x.splice(1, 2);
// below display kind of a different result
console.debug('debug', x);
console.log('log', x);
Run Code Online (Sandbox Code Playgroud)
alt text http://sixbytesunder.com/stuff/firebug_console.png
javascript值完全相同,但console.log()显示它与应用splice()方法之前有点不同.因为这个我失去了几个小时,因为我认为拼接是有趣的使我的阵列多维或其他东西.
我只是想知道为什么这样的工作.有人知道吗?:)
这似乎是一个基本的问题,但在搜索了一段时间并使用它之后,我已经到了可以欣赏一些帮助的地步.我想让一个SensorEventListener在一个与UI不同的线程中运行,这样当事件进入时需要进行的计算不会减慢UI的速度.
我最近的尝试看起来像:
class SensorThread extends Thread {
SensorManager mSensorManager;
Sensor mSensor;
public void run() {
Log.d( "RunTag", Thread.currentThread().getName() ); // To display thread
mSensorManager = (SensorManager)getSystemService( SENSOR_SERVICE );
mSensor = mSensorManager.getDefaultSensor( Sensor.TYPE_ACCELEROMETER );
MySensorListener msl = new MySensorListener();
mSensorManager.registerListener(msl, mSensor, SensorManager.SENSOR_DELAY_UI );
}
private class MySensorListener implements SensorEventListener {
public void onAccuracyChanged (Sensor sensor, int accuracy) {}
public void onSensorChanged(SensorEvent sensorEvent) {
Log.d( "ListenerTag", Thread.currentThread().getName() ); // To display thread
}
}
Run Code Online (Sandbox Code Playgroud)
在活动(或服务)onCreate()中,我创建了一个SensorThread对象并调用其start()方法.正如您所料,调试日志显示新线程中的"RunTag"条目.但onSensorChanged()的"ListenerTag"正在主线程中运行,即使它的对象在新线程中实例化.我该如何改变?
我有一个服务,它会创建一个通知,然后定期用某些信息更新它.电话崩溃并重新启动大约12分钟后,我认为这是由于以下代码中的内存泄漏导致我如何更新通知,有人请检查/建议我是否是这种情况和我我做错了.
的onCreate:
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Run Code Online (Sandbox Code Playgroud)
createNotification:
private void createNotification() {
Intent contentIntent = new Intent(this,MainScreen.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent appIntent =PendingIntent.getActivity(this,0, contentIntent, 0);
contentView = new RemoteViews(getPackageName(), R.layout.notification);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, "");
notification = new Notification();
notification.when=System.currentTimeMillis();
notification.contentView = contentView;
notification.contentIntent = appIntent;
}
Run Code Online (Sandbox Code Playgroud)
updateNotification:
private void updateNotification(String text){
contentView.setTextViewText(R.id.text, text);
mNotificationManager.notify(0, notification);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
有些人可以向我解释一下是做什么的
@XmlElementRefs
Run Code Online (Sandbox Code Playgroud)
和
@XmlElementRef
Run Code Online (Sandbox Code Playgroud)
注释在Java中意味着什么是它们的用途..
编辑: @skaffman
好吧,假设我有一个这样的集合
@XmlElementRefs({
@XmlElementRef(name="ElementA", type=ClassA),
@XmlElementRef(name="ElementB", type=ClassB) }
)
List<Object> items;
Run Code Online (Sandbox Code Playgroud)
现在我如何访问此列表中的每个元素?以下代码是否正确?
for (int j = 0; j < items.size(); ++j) {
if (items.get(i).getClass().equals(ClassA)) {
// perform ClassA specific processing:
} else if (items.get(i).getClass().equals(ClassB)) {
// perform ClassB specific processing:
}
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?有没有更好的方法来执行每个类特定的处理?我的意思是有办法避免这些if else结构吗?
每当我需要提交文件时,我发现它很乏味.进程转到Windows资源管理器窗口,右键单击目录,然后单击"提交"...然后是tortoisesvn提交窗口.
有人知道这样做的任何捷径吗?也许按键盘快捷键提交而不必右键单击目录然后单击提交?
感谢您节省我的工作效率!
我为一家公司工作,该公司编写的软件客户端网站嵌入了<script language ="JavaScript"src = .....等等.我们非常依赖document.write将元素写入页面.由于某种原因,我们的一个客户选择使用内容类型"application/xhtml + xml",这使得document.write()在chrome中无法使用.
我理解为什么会这样,并且符合DOM的代码应该创建每个元素,设置其属性,如果需要填充文本节点,将文本节点附加到其父节点,将父节点附加到某个页面元素....
但是什么是一个好的解决方法,不需要所有这些垃圾?其中的write()有很多元素,如果我们制作节点并将它们固定在一起,就像Knex或Legos或者你有什么,那么生成的代码将是可怕的.
编辑:尝试使用CDATA,但即使这行也被我们的脚本嵌入在同一页面上的xhtml解析器类似地谴责:
<script language="text/javascript"><![CDATA[document.write('hi');]]></script>
Run Code Online (Sandbox Code Playgroud) javascript ×3
android ×2
firefox ×2
java ×2
svn ×2
tortoisesvn ×2
collections ×1
console ×1
delete-file ×1
events ×1
file ×1
firebug ×1
jaxb ×1
list ×1
memory-leaks ×1
null ×1
terminology ×1
time ×1
xhtml ×1
xml ×1
xul ×1