首页 | 本学科首页   官方微博 | 高级检索  
相似文献
 共查询到16条相似文献,搜索用时 125 毫秒
1.
Java泛型研究     
林帅  林雄 《电脑开发与应用》2012,25(3):63-65,68
2004年2月,Sun公司(2010年10月已被Oracle收购)在它发布的J2SE1.5版中加入了泛型,允许对类型进行抽象,程序员只需声明一个接受可变数目参数的方法,便可得到强类型在编译时刻进行类型检查的好处,简化了程序的开发。阐述了泛型基本概念和作用,介绍了在Java类、接口和方法中使用泛型的方法,通过实例比较使用泛型和不使用泛型的区别,最后指出使用泛型时要注意的问题。  相似文献   

2.
张冬姣  陈艳 《福建电脑》2011,27(12):144-145
泛型是Java SE 1.5的新特性,泛型的参数化类型是Java语言中类型安全的一次重要改进。但是,对于初次使用泛型的用户来说,泛型的某些方面看起来可能不容易明白,也不容易掌握,因此本文开始简单的介绍了泛型,然后从协变性、类型擦除和通配符三个角度来让大家快速理解泛型。  相似文献   

3.
史浩 《福建电脑》2014,(11):85-87
VS C#多文档界面MDI窗体程序中创建子窗体可以有多种实现方式,通过对于泛型实现的详细介绍,不但体现其代码的简洁易维护,而且对于了解如何使用泛型有一定帮助。除此之外,还应用多态及反射两种方式实现了子窗体的展现并比较了其各自使用的特点。  相似文献   

4.
你知道吗?Java SDK的最新版本(JDK1.5,代号为Tiger)里面将会出现泛型(Gernerics)。你可能会疑惑:“什么是泛型?”,或者是“为什么我应该注意泛型?”,甚至是“真酷!怎么使用泛型?”本文将介绍泛型编程、泛型如何使用,以及泛型的优势何在,并讨论泛型将如何的影响到你的工作。为了便于理解,这里给泛型下了一个定义,并给出几个例子来说明如何使用泛型。泛型并不是人人都使用过的一个特性。C++里面有一个类似于泛型的概念:模板。尽管。Java泛型的语法是模仿C++模板的语法,但是、Java语法更易于理解。另外,模板和泛型的执行过程并不相同。Java保留了safe类型,而且当支持泛型时,Java并不暴露源代码。也就是,Java说,Java增加了泛型编程的威力,而并没有出现其它应用语言所出现的诸多问题。  相似文献   

5.
刘峻 《计算机仿真》2005,22(3):232-235
该文围绕即将加入Java语言规范的泛型特性进行了讨论,JSR-14就是这一特性的实现。文章首先展示了在Java中使用泛型的语法,包括泛型类、泛型方法以及极具特色的受限类型参数;然后深入揭示了JSR-14实现泛型的内部机制——用擦拭法将源文件翻译成为与原先字节代码兼容的形式。并讨论了在不同情况下擦拭法的具体实现方式;最后讨论了该实现的优点和限制。着重分析了它的限制,指出这些限制正是由于擦拭法所产生的,并分别分析了每种限制的具体原因。  相似文献   

6.
泛型是Java SE 1.5的新特性,从表面上看,无论语法还是应用的环境,泛型类型(或者泛型)都类似于C++中的模板,但实际上它们之间有着本质的区别,其本质区别就在于Java泛型的类型擦除,本文重点介绍Java泛型的类型擦除以解决泛型中常见的令人迷惑的和使人头疼的问题。  相似文献   

7.
泛型程序设计将类型安全的任务从程序员转移给编译器,不再需要程序员编写代码来检测数据类型是否正确,而是在编译时由编译器强制使用正确的数据类型。因此,采用泛型程序设计可以减少类型强制转换的需要和运行时出现错误的可能性。  相似文献   

8.
一种有效的ASP.NET数据缓存方法   总被引:1,自引:0,他引:1  
分析比较了ASENET中常用的内置缓存技术及使用场合,在此基础上提出了一种新的基于泛型技术的缓存方法。新方法通过泛型技术与静态方法的结合,达到了对缓存数据的强类型引用,避免了装箱/拆箱操作,提高了系统的性能,并可由开发者根据不同情况自行配置缓存。最后分析了新方法的优缺点及适用场合。  相似文献   

9.
分析非泛型的Java系统存在的数据类型转换安全问题,提出基于Java泛型的解决方案。通过对泛型的原理分析,探讨Java泛型的实际应用。并在此基础上,总结Java泛型的的特点。  相似文献   

10.
Java泛型应用研究   总被引:1,自引:0,他引:1  
分析非泛型的Java系统存在的数据类型转换安全问题,提出基于Java泛型的解决方案。通过对泛型的原理分析,探讨Java泛型的实际应用。并在此基础上,总结Java泛型的的特点。  相似文献   

11.
In response to a long-lasting anticipation by the Java community, version 1.5 of the Java 2 platform - referred to as Java 5 - introduced generic types and methods to the Java language. The Java 5 generics are a significant enhancement to the language expressivity because they allow straightforward composition of new generic classes from existing ones while reducing the need for a plethora of type casts. While the Java 5 generics are expressive, the chosen implementation method, type erasure, has triggered undesirable orthogonality violations. This paper identifies six cases of orthogonality violations in the Java 5 generics and demonstrates how these violations are mandated by the use of type erasure. The paper also compares the Java 5 cases of orthogonality violations to compatible cases in C# 2 and NextGen 2 and analyzes the tradeoffs in the three approaches. The conclusion is that Java 5 users face new challenges: a number of generic type expressions are forbidden, while others that are allowed are left unchecked by the compiler.  相似文献   

12.
After several years from Sun Microsystems' call-for-proposals for adding generics to the Java Programming Language, JDK 1.5 will be finally shipped with a compile-time support for generics. However, differently e.g. from the current implementation of .NET Common Language Runtime, run-time support to generics — also commonly referred to as reification of type parameters — is not provided, leading to a number of well-known inadequacies which might potentially be critical. In this paper we present the EGO compiler (Exact Generics on Demand). This is the result of a project developed in collaboration with Sun Microsystems as an effort to provide run-time generics in a smooth way, without requiring any change on the JVM or on any other run-time support. The core solution is a sophisticated translation of code based on the type-passing style, where run-time type information is automatically created on a by-need basis, limiting as most as possible run-time overhead while retaining interoperability with legacy Java code.We present the main aspects of this development, from basic design to implementation and deployment issues. Many relevant aspects that typical raise when implementing advanced type systems over a mainstream programming language are discussed, shading light to some effective implementation techniques.  相似文献   

13.
Support for generic programming was added to the Java language in 2004, representing perhaps the most significant change to one of the most widely used programming languages today. Researchers and language designers anticipated this addition would relieve many long-standing problems plaguing developers, but surprisingly, no one has yet measured how generics have been adopted and used in practice. In this paper, we report on the first empirical investigation into how Java generics have been integrated into open source software by automatically mining the history of 40 popular open source Java programs, traversing more than 650 million lines of code in the process. We evaluate five hypotheses and research questions about how Java developers use generics. For example, our results suggest that generics sometimes reduce the number of type casts and that generics are usually adopted by a single champion in a project, rather than all committers. We also offer insights into why some features may be adopted sooner and others features may be held back.  相似文献   

14.
Generic programming is an effective methodology for developing reusable software libraries. Many programming languages provide generics and have features for describing interfaces, but none completely support the idioms used in generic programming. To address this need we developed the language G. The central feature of G is the concept, a mechanism for organizing constraints on generics that is inspired by the needs of modern C++ libraries. G provides modular type checking and separate compilation (even of generics). These characteristics support modular software development, especially the smooth integration of independently developed components. In this article we present the rationale for the design of G and demonstrate the expressiveness of G with two case studies: porting the Standard Template Library and the Boost Graph Library from C++ to G. The design of G shares much in common with the concept extension proposed for the next C++ Standard (the authors participated in its design) but there are important differences described in this article.  相似文献   

15.
We present a graph-basedmodel of a generic type system for an OO language. The type system supports the features of recursive types, generics and interfaces, which are commonly found in modern OO languages such as Java. In the classical graph theory, we define type graphs, instantiation graphs and conjunction graphs that naturally illustrate the relations among types, generics and interfaces within complex OO programs. The model employs a combination of nominal and anonymous nodes to represent respectively types that are identified by names and structures, and defines graph-based relations and operations on types including equivalence, subtyping, conjunction and instantiation. Algorithms based on the graph structures are designed for the implementation of the type system. We believe that this type system is important for the development of a graph-based logical foundation of a formal method for verification of and reasoning about OO programs.  相似文献   

16.

In the domain of web security, websites strive to prevent themselves from data gathering performed by automatic programs called bots. In that way, crawler traps are an efficient brake against this kind of programs. By creating similar pages or random content dynamically, crawler traps give fake information to the bot and resulting by wasting time and resources. Nowadays, there is no available bots able to detect the presence of a crawler trap. Our aim was to find a generic solution to escape any type of crawler trap. Since the random generation is potentially endless, the only way to perform crawler trap detection is on the fly. Using machine learning, it is possible to compute the comparison between datasets of webpages extracted from regular websites from those generated by crawler traps. Since machine learning requires to use distances, we designed our system using information theory. We considered widely used distances compared to a new one designed to take into account heterogeneous data. Indeed, two pages does not have necessary the same words and it is operationally impossible to know all possible words by advance. To solve our problematic, our new distance compares two webpages and the results showed that our distance is more accurate than other tested distances. By extension, we can say that our distance has a much larger potential range than just crawler traps detection. This opens many new possibilities in the scope of data classification and data mining.

  相似文献   

设为首页 | 免责声明 | 关于勤云 | 加入收藏

Copyright©北京勤云科技发展有限公司  京ICP备09084417号