程序设计

专业和发烧友程序员的问答

27
在Java中创建泛型类型的实例?
是否可以在Java中创建泛型类型的实例?我正在根据我所看到的答案进行思考no(由于类型删除),但是如果有人能看到我所缺少的内容,我将很感兴趣: class SomeContainer<E> { E createContents() { return what??? } } 编辑:事实证明 超级类型令牌可以用来解决我的问题,但是它需要很多基于反射的代码,如下面的一些答案所示。 我将对此开放一会儿,看看是否有人提出与Ian Robertson的Artima Article截然不同的东西。
576 java  generics 

13
PNG,GIF,JPEG,SVG有哪些不同的用例?
建立网站或界面等时应何时使用某些图像文件类型? 他们的优点和缺点是什么? 我知道PNG和GIF无损,而JPEG有损。 但是PNG和GIF之间的主要区别是什么? 为什么我要一个比另一个更好?什么是SVG?何时使用? 如果您不关心每个像素,是否应该始终使用JPEG,因为它是“最轻”的像素?
575 image  svg  png  jpeg  gif 


29
在Swift中使用dispatch_once单例模型
我正在尝试制定一个合适的单例模型以在Swift中使用。到目前为止,我已经能够获得一个非线程安全模型,其工作方式如下: class var sharedInstance: TPScopeManager { get { struct Static { static var instance: TPScopeManager? = nil } if !Static.instance { Static.instance = TPScopeManager() } return Static.instance! } } 在静态结构中包装单例实例应该允许一个不与单例实例冲突的单实例,而无需复杂的命名方案,这应该使事情变得相当私有。但是,显然,此模型不是线程安全的。所以我尝试添加dispatch_once到整个事情: class var sharedInstance: TPScopeManager { get { struct Static { static var instance: TPScopeManager? = nil static var token: dispatch_once_t …




30
Bootstrap模态出现在背景下
我直接从Bootstrap示例中使用了模态代码,仅包含bootstrap.js(而不包含bootstrap-modal.js)。但是,我的模态出现在灰色渐变(背景)下面,并且不可编辑。 看起来是这样的: 请参阅此提琴,以获取重现此问题的一种方法。该代码的基本结构如下: <body> <p>Lorem ipsum dolor sit amet.</p> <div class="my-module"> This container contains the modal code. <div class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body">Modal</div> </div> </div> </div> </div> </body> body { padding-top: 50px; } .my-module { position: fixed; top: 0; left: 0; } 关于这是为什么的任何想法,或者我可以做些什么来解决此问题?

11
遍历Java中的列表的方法
对于Java语言有些陌生,我试图使自己熟悉所有可能遍历列表(或其他集合)的方式(或至少是非病理性方式)以及每种方式的优缺点。 给定一个List<E> list对象,我知道以下遍历所有元素的方式: 基本的for 循环(当然,也有等效的while/ do while循环) // Not recommended (see below)! for (int i = 0; i < list.size(); i++) { E element = list.get(i); // 1 - can call methods of element // 2 - can use 'i' to make index-based calls to methods of list // ... …

11
如何在JavaScript中进行关联数组/哈希
我需要使用JavaScript来存储一些统计信息,就像在C#中那样: Dictionary<string, int> statistics; statistics["Foo"] = 10; statistics["Goo"] = statistics["Goo"] + 1; statistics.Add("Zoo", 1); JavaScript中是否有Hashtable类似的东西Dictionary<TKey, TValue>? 如何以这种方式存储值?

9
如何将字符串拆分为列表?
我希望我的Python函数拆分一个句子(输入)并将每个单词存储在列表中。我当前的代码拆分了句子,但没有将单词存储为列表。我怎么做? def split_line(text): # split the text words = text.split() # for each word in the line: for word in words: # print the word print(words)


30
获取具有列最大值的行
表: UserId, Value, Date. 我想获取UserId,每个UserId的max(Date)值。即,具有最新日期的每个UserId的值。有没有办法在SQL中简单地做到这一点?(最好是Oracle) 更新:对于任何歧义,我们深表歉意:我需要获取所有UserIds。但是对于每个UserId,仅该用户具有最新日期的那一行。


18
如何检查JavaScript中的空值?
如何在JavaScript中检查空值?我在下面编写了代码,但是没有用。 if (pass == null || cpass == null || email == null || cemail == null || user == null) { alert("fill all columns"); return false; } 在JavaScript程序中如何找到错误?
573 javascript  null  compare 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.