Created
May 17, 2017 21:26
-
-
Save fermopili/3817c2b7abc3307ca5de975935a654c7 to your computer and use it in GitHub Desktop.
com.javarush.task.task35.task3503 Несколько суперклассов для дженерика
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task35.task3503; | |
public class ClassForGenerics { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task35.task3503; | |
public interface InterfaceForGenerics { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task35.task3503; | |
/* | |
Несколько суперклассов для дженерика | |
*/ | |
public class Solution<T extends ClassForGenerics & InterfaceForGenerics> | |
{ | |
public static void main(String[] args) | |
{ | |
Solution<TestClassGood> testClassSolution = new Solution<> ( ); | |
testClassSolution.check ( ); | |
//!!! Следующие оба варианта не должны работать, закомментируй их: | |
// Solution<TestClassWrong1> wrong1Solution = new Solution<> ( ); | |
// wrong1Solution.check ( ); | |
// Solution<TestClassWrong2> wrong2Solution = new Solution<> ( ); | |
// wrong2Solution.check ( ); | |
} | |
public void check() | |
{ | |
System.out.println ("Works!"); | |
} | |
public static class TestClassGood extends ClassForGenerics implements InterfaceForGenerics | |
{ | |
} | |
public static class TestClassWrong1 extends ClassForGenerics | |
{ | |
} | |
public static class TestClassWrong2 implements InterfaceForGenerics | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
taskKey="com.javarush.task.task35.task3503" | |
Несколько суперклассов для дженерика | |
Дан класс Solution, параметризированный T. | |
Ограничьте параметр T. | |
T должен быть наследником класса ClassForGenerics и одновременно реализовывать интерфейс InterfaceForGenerics. | |
Менять можно только класс Solution. | |
Требования: | |
1. Класс Solution должен быть параметризирован типом который является наследником класса ClassForGenerics и одновременно реализовывать интерфейс InterfaceForGenerics. | |
2. Интерфейс InterfaceForGenerics не должен расширять другие интерфейсы. | |
3. Класс ClassForGenerics не должен поддерживать интерфейс InterfaceForGenerics. | |
4. Класс Solution не должен быть наследником класса ClassForGenerics. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment