首页 | 本学科首页   官方微博 | 高级检索  
相似文献
 共查询到19条相似文献,搜索用时 103 毫秒
1.
王朋  徐健  于尚超 《微机发展》2013,(7):92-95,100
泛型编程旨在编写一般化并可重复使用的算法,主要目的是提高程序的复用性,其效率与针对某特定数据类型而设计的算法相同。泛型编程可以使算法与数据结构完全分离,极大提高了程序的灵活性。在O’Caml语言中已经实现了类型标记函数和泛型函数,但泛型函数的类型参数只能是基本类型或实例化类型,不能使用抽象类型。"泛型抽象"是指使用抽象类型作为类型参数的函数定义方法,实现了"泛型编程"类型参数的多样化。文中在O’Caml语言上进行"泛型抽象"的研究,根据规则对O’Caml语言语法进行扩展,并在O’Caml语言中实现了"泛型抽象"函数定义。  相似文献   

2.
泛型编程旨在编写一般化并可重复使用的算法,主要目的是提高程序的复用性,其效率与针对某特定数据类型而设计的算法相同.泛型编程可以使算法与数据结构完全分离,极大提高了程序的灵活性.在O'Caml语言中已经实现了类型标记函数和泛型函数,但泛型函数的类型参数只能是基本类型或实例化类型,不能使用抽象类型.“泛型抽象”是指使用抽象类型作为类型参数的函数定义方法,实现了“泛型编程”类型参数的多样化.文中在O'Caml语言上进行“泛型抽象”的研究,根据规则对O'Caml语言语法进行扩展,并在O'Caml语言中实现了“泛型抽象”函数定义.  相似文献   

3.
本文阐述了Java中泛型的概念和特点,介绍了简单泛型创建和使用,探讨了泛型应用中存在的陷井。泛型最重要的特点是类型安全,泛型还可以消除类型转换等。泛型的创建和使用比较简单,但在使用中存在一定的陷阱,需要引起程序员的注意。  相似文献   

4.
基于源代码静态分析的C++0x泛型概念抽取   总被引:1,自引:0,他引:1  
使用泛型概念对领域知识进行抽象是泛型程序设计方法的基础.在新的C++0x标准中泛型概念将成为一个新的语言设施,这将为设计可复用、可扩展的泛型软件提供坚实的基础.为了更好地利用C++0x的新特性,有必要识别C++遗产代码中的泛型概念,并通过重构得到符合C++0x标准的代码.文中提出了一种基于代码静态分析的泛型概念自动识别方法,通过对泛型程序中类型参数的使用分析,从遗产代码中提取有效表达式约束和关联类型约束,进而推导出泛型概念.将该方法应用于C++标准模板库STL,可以识别出STL算法中绝大部分潜在的泛型概念,表明该方法有助于识别遗产代码中的泛型概念.  相似文献   

5.
在.Net开发中,经常会需要使用集合类来存储对象。在.Net框架类库中提供了通用集合类,从.Net 2.0开始,又提供了泛型,对自定义集合类和泛型集合类进行了比较,认为在.Net开发中使用泛型集合类可以极大提高开发的效率、程序可读性和类型安全性。  相似文献   

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

7.
对于泛型程序设计来说,类型的参数化多态是其理论框架,参数化多态引入了类型变量,使得类型参数化,支持类型上的抽象,从而可以大大提高软件的复用程度。泛型编程思想已经在多种语言中得到运用,并已取得了不小的成果。在函数式语言上进行泛型的研究与应用,Haskell语言是函数式语言中较为经典的一种语言,它的计算模型简单,语法清晰,易于编写,易于维护,拥有很大的发展空间。利用一些规则对Haskell语言的语法进行相关扩展,同时引入泛型的思想,研究与运用定义泛型函数的方法,在Haskell语言上实现了泛型功能。  相似文献   

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

9.
陈林  徐宝文  钱巨  周天琳  周毓明 《软件学报》2009,20(10):2617-2627
重构泛型实例有利于提高软件的复用性和类型安全,但现有重构方法的时间复杂度较高,不适用于即时持续的重构.分析了变量类型传播分析方法在重构中的不足,提出了一种改进的泛型变量类型传播分析方法.该方法通过引入一种可以描述复杂参数化类型关系的泛型类型传播图,以复制节点的方式实现泛型变量属性敏感的类型分析,并通过解决别名问题来提高分析的精度.实例研究表明,可以在与程序规模呈近似线性增长的时间复杂度内实施重构,取得了较满意的效果.  相似文献   

10.
泛型即通过参数化类型来实现在同一份代码上操作多种数据类型.泛型编程是一种编程范式,它利用“参数化类型”将类型抽象化,实现灵活的软件复用.泛型编程思想已经在多种语言中得到运用,并已取得了不小的成果.文中旨在Haskell语言上进行泛型的研究与应用,Haskell语言是一门广为流行的函数式语言,它的计算模型简单,程序语法清晰,易于编写,易于维护.文中利用一些规则对Haskell语言的语法进行扩展,同时引入泛型编程的思想来研究新的函数定义方法,最后在Haskell语言上实现泛型功能.  相似文献   

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

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

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.
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.  相似文献   

15.
Type-directed programming is an important and widely used paradigm in the design of software. With this form of programming, an application may analyze type information to determine its behavior. By analyzing the structure of data, many operations, such as serialization, cloning, adaptors and iterators may be defined once, for all types of data. That way, as the program evolves, these operations need not be updated—they will automatically adapt to new data forms. Otherwise, each of these operations must be individually redefined for each type of data, forcing programmers to revisit the same program logic many times during a program's lifetime.The Java language supports type directed programming with the instanceof operator and the Java Reflection API. These mechanisms allow Java programs to depend on the name and structure of the run-time classes of objects. However, the Java mechanisms for type-directed programming are difficult to use. They also do not integrate well with generics, an important new feature of the Java language.In this paper, we describe the design of several expressive new mechanisms for type-directed programming in Java, and show that these mechanisms are sound when included in a language similar to Featherweight Java. Basically, these new mechanisms pattern-match the name and structure of the type parameters of generic code, instead of the run-time classes of objects. Therefore, they naturally integrate with generics and provide strong guarantees about program correctness. As these mechanisms are based on pattern matching, they naturally and succinctly express many operations that depend on type information. Finally, they provide programmers with some degree of protection for their abstractions. Whereas instanceof and reflection can determine the exact run-time type of an object, our mechanisms allow any supertype to be supplied for analysis, hiding its precise structure.  相似文献   

16.
泛型编程是面向对象的进一步发展,从更高的角度对世界进行抽象,为面向对象的不足之处提供了解决之道.它可让你重复运用既有的算法,而不必在环境类似的情况下再重新撰写相同代码,使得处理的问题更加抽象化,是一种优美而又不失效率的通用型程序设计方法.JDK 1.5中引入了对Java语言的多种扩展,泛型(generics)即其中之一.本文讨论JDK 1.5的泛型实现.  相似文献   

17.
使用Stripes开发Web应用   总被引:1,自引:0,他引:1  
Stripes是一种基于Java语言的Web应用框架,它充分利用了Java5的注释和泛化特性,使开发者不必维护外部配置文件,提高了开发效率。本文阐述了Stripes框架的工作原理,并且应用Stripes框架设计了一个简单的Web应用。  相似文献   

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

19.
This paper presents Java language from an object-oriented software construction perspective. It explains the implications of banning generics and multiple inheritance of classes, and explores the patterns and the idioms used by the Java designers and programmers to redeem their benefits. The paper also discusses an alternative to multiple inheritance, as incorporated in Lava, which extends Java with constructs for type-safe automatic forwarding.  相似文献   

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

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