泛型的使用主要有两种:泛型类和泛型方法
泛型类
public class GeneralClass<T> {
...
}
package playground | |
import scala.util.{Failure, Success, Try} | |
object ParserCombinator { | |
def theLetterA(input: String): Try[(String, Unit)] = { | |
input.toList match { | |
case first :: rest if first == 'a' => Success((rest.mkString, ())) | |
case _ => Failure(ParseError(input)) |
<!DOCTYPE html> | |
<html lang='en-US'> | |
<head> | |
<meta charset='utf-8'> | |
<meta http-equiv='X-UA-Compatible' content='IE=edge'> | |
<meta name='viewport' content='width=device-width, initial-scale=1'> | |
<link rel='stylesheet' href='https://pingao777.github.io/github-gazer/assets/css/style.css?v=83f9436b2e1b1a48c5227dc3037dbc5f1a9b5db1'> | |
<!-- Begin Jekyll SEO tag v2.5.0 --> | |
<title>Let the world witness the history of your repository | github-gazer</title> | |
<meta name='generator' content='Jekyll v3.7.3.1'/> |