如何编码MyClass <integer>

时间:2015-11-13 00:55:05

标签: java

下面我有2节课。 “run”类是主类,它将调用'MyClass'类。

问题:如何更改“MyClass”以便我可以使用MyClass<Integer>

错误:在运行类中,因为我使用的是<Integer>

public class ran {
    public static void main(String[] args){
        MyClass<Integer> m = new MyClass<Integer>();

    }
}


public class MyClass{
    public MyClass(int n){}
}

1 个答案:

答案 0 :(得分:0)

以下是泛型的简单用法。 T是一个模板类,我们可以使用Integer,Float等。

-- Initial Buggy.cabal generated by cabal init.  For further documentation,
--  see http://haskell.org/cabal/users-guide/

name:                Buggy
version:             0.1.0.0
-- synopsis:
-- description:
-- license:
license-file:        LICENSE
author:              Luka Horvat
maintainer:          lukahorvat9@gmail.com
-- copyright:
-- category:
build-type:          Simple
-- extra-source-files:
cabal-version:       >=1.10

executable Buggy
  main-is:             Main.hs
  c-sources:           clipper.cpp
                     , wrapper.cpp
  -- other-modules:
  -- other-extensions:
  build-depends:       base >=4.8 && <4.9
  -- hs-source-dirs:
  default-language:    Haskell2010
  extra-libraries:     stdc++