ASDV-Java/Semester 3/Assignments/lab6_generics_CalebFontenot/Printed HTMLs/WildCardWithSuper.html
2023-09-22 16:25:19 -05:00

53 lines
2.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>WildCardWithSuper.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.literal {color: #cc7832}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/lab6_generics_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab6_generics_calebfontenot/WildCardWithSuper.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.lab6_generics_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> WildCardWithSuper {
<span class="literal">public</span> <span class="literal">static</span> &lt;T&gt; <span class="literal">void</span> add(GenericStack&lt;T&gt; stack1, GenericStack&lt;? <span class="literal">super</span> T&gt; stack2) {
<span class="literal">while</span>(!stack1.isEmpty()) {
stack2.push(stack1.pop());
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
GenericStack&lt;String&gt; stack1 = <span class="literal">new</span> GenericStack&lt;&gt;();
GenericStack&lt;Object&gt; stack2 = <span class="literal">new</span> GenericStack&lt;&gt;();
stack2.push(<span class="string">&quot;</span><span class="string">one</span><span class="string">&quot;</span>);
stack2.push(<span class="number">2</span>);
stack1.push(<span class="string">&quot;</span><span class="string">one</span><span class="string">&quot;</span>);
add(stack1, stack2);
WildCard2.print(stack2);
}
}
</pre></body>
</html>