Comparison of Java and C++: Difference between revisions

Content deleted Content added
Cleaned up references section to be consistent with other articles
Templates vs. generics: Added updated C++ info with concepts
Tags: Mobile edit Mobile web edit
Line 369:
| Wildcards supported as type parameter.
|-
| NoBounding directof supporttype forparameters boundingand enforcement of relationships between type parameters, buteffectively metaprogrammingpossible providesthrough metaprogramming this<ref>[http://www.boost.org/libs/type_traits/doc/html/boost_typetraits/reference.html Boost type traits library]</ref>, or since C++20, directly via <code>std::derived_from</code> and other [[Concepts (C++)|concepts]]
| Supports bounding of type parameters with "extends" and "super" for upper and lower bounds, respectively; allows enforcement of relationships between type parameters.
|-
Line 381:
| Static variables shared between instances of classes of different type parameters.
|-
| Class and function templates do not necessarily enforce type relations for type parameters in their declaration. Use of an incorrect type parameter results in compiling failure, often generating an error message within the template code rather than in the user's code that invokes it. Proper use of templated classes and functions is dependent on proper documentation. Metaprogramming provides these features at the cost of added effort. ThereSince was a proposition to solve this problem in [[C++11]]20, so-called [[Concepts (C++)|Conceptsconcepts]], itcan isbe plannedused forto theprovide nextthese standardfeatures.
| Generic classes and functions can enforce type relationships for type parameters in their declaration. Use of an incorrect type parameter results in a type error within the code that uses it. Operations on parametrized types in generic code are only allowed in ways that can be guaranteed to be safe by the declaration. This results in greater type safety at the cost of flexibility.
|-