This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
The constructor Date(…) is deprecated. What does it mean? (Java)
When I use SMSManager object on Android, Eclipse notice that this class is deprecate and there is a crossline at SMSManager, but everything works normally.
Who can explain for me this, please.
thanks :)
#Deprecated
A program element annotated #Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code.
A deprecated class or method is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. It is so potentially bad/out-dated, in fact, that you should no longer use it, since it has been superseded and may cease to exist in the future.
Deprecated means it will no longer be supported in the future. See the documentation http://developer.android.com/reference/android/telephony/gsm/SmsManager.html
This class is deprecated.
Replaced by android.telephony.SmsManager that supports both GSM and CDMA.
This class is deprecated.
Replaced by android.telephony.SmsManager that supports both GSM and CDMA.
See here
Deprecation doesn't mean that the Object isn't working anymore, it means that a new one exists now and that you should be using that new one. In your case, you should use android.telephony.SMSManager and not android.telephony.gsm.SMSManager.
Related
This question already has answers here:
Which types can be used for Java annotation members?
(4 answers)
Closed 4 years ago.
Can I able to call a method which returns string inside an annotation.
If so please guide me how to achieve this?
I tried like this but this doesn't work for me.
#Description(value = Resource.getWord("key"))
An annotation only takes compile time constants (as they might be used during compile time), therefore you cannot make any calculation within the definition, as they are unknown during the compile time.
Allowed constant types are (taken from java-annotation-members):
Primitive
String
Class
Enum
Another Annotation
An array of any of the above
Possible solution for your situation:
As I understand you would like to localize the #Description content.
As this is only meant to be exposed to other developers anyway, you are safe to simply use English, in my opinion. Localization is for the end user, not the developer.
I can imagine an aspect being wired up to process methods annotated like this, where the "key" is in the annotation, and the aspect processing then uses the key at run time... but I'm not sure this is what you're looking for.
This question already has answers here:
What is the "default" implementation of method defined in an Interface?
(3 answers)
Closed 6 years ago.
I was studying lambada and there was a point which states that in java 8 we can declare a method with definition in interfaces like
interface Test {
default String method(){
return "string";
}
}
and as per specification we can use two methods with same signature but depends on programmer how he wants to use it?
Now the question is same task can be if achieved by using definition not declaration then what's the point of using default method?
like they behave same as regular method definition and programmer need to declare body and rest part?
what is the actual point as it seems a bit hard to grasp
thanks #ElliottFrisch and #kagemusha for hint after searching i got the answer
Why default methods?
List<?> list = …
list.forEach(…); // lambda code goes here
The forEach isn’t declared by java.util.List nor the java.util.Collection interface yet. One obvious solution would be to just add the new method to the existing interface and provide the implementation where required in the JDK. However, once published, it is impossible to add methods to an interface without breaking the existing implementation.
So it’d be really frustrating if we have lambdas in Java 8 but couldn’t use those with the standard collections library since backwards compatibility can’t be sacrificed.
Due to the problem described above a new concept was introduced. Virtual extension methods, or, as they are often called, defender methods, can now be added to interfaces providing a default implementation of the declared behavior.
Simply speaking, interfaces in Java can now implement methods. The benefit that default methods bring is that now it’s possible to add a new default method to the interface and it doesn’t break the implementations.
It doesn’t seem to be the language feature that would be appropriate to use every day, but it seems to be essential for Java Collections API update to be able to use lambdas naturally.
This question already has answers here:
Do Java 8 default methods break source compatibility?
(5 answers)
Closed 6 years ago.
So as far as I know, the main idea behind the new interface default methods of Java 8 is to support Interface Evolution, i.e. extend an interface without braking existing implementations.
But what just occurred to me is that actually all these new default interface methods in the API hava a potential to break existing code. Namely, my implementation breaks if in a class I am implementing an interface X, and that interface X now has a new default method, which has the same signature than some private instance method of my class that already existed! Because in this case the compiler thinks I'm overriding the interface method while reducing its visibility, which is not allowed. So what if I have some implementation of Iterable and came up with some private forEach utility method? No when I update to Java 8 I can no longer compile.
Is it just me that is a bit shocked that Oracle actually released a not fully downwards-compatible API update? Has something like this ever happened in the past, that upgrading to a new compilation version can make some of your code no longer compile? Because if so I'm not aware of it. And what are your opinions of this?
edit: Oh, wait, what I said might have a flaw.. I mentioned the example with the Iterable#forEach method, but actually, this method takes some parameter that is also only introduced with Java 8. So there is no way that I could have defined such a method previously. Now, my next question: Could it be that ALL new default methods take some new type to guarantee they cannot collide with any pre-Java-8 existing instance method?
Cheers
Oracle had to choose between letting the language and APIs stagnate, or risk some backward incompatibilities. Yes, default methods can cause problems with existing extending interfaces and implementations. That's well known.
Has that already happened in the past? Yes: the JDBC interfaces have several times had new methods. assert was not a keyword but is one since Java 1.4, etc. enum was not a keyword before 1.5, etc.
EDIT
Examples of backward incompatibilities:
If you have an interface MyCollection extending Collection and having a method stream(), it will conflict with the new default stream() method, because it has the same signature but a different return type.
If you have an interface or class extending/implementing List<E> and having a method void sort(Comparator<E> c), it will conflict with the new default method void sort(Comparator<? super E>).
So what if I have some implementation of Iterable and came up with some private forEach utility method?
This isn't a problem because this would only overload the method. You can't have a forEach(Consumer) as this interface didn't exist before.
Is it just me that is a bit shocked that Oracle actually released a not fully downwards-compatible API update?
In each major version there is changes which could break backward compatibility, In Java 1.4, the keyword enum was added which meant if you have a variable called enum it would break.
Has something like this ever happened in the past, that upgrading to a new compilation version can make some of your code no longer compile?
Some APIs have changed, one of the oldest changes was a fix to String.hashCode() in Java 1.2.
In my opinion this Default method stuff should not be used by us Java developers. This was probably the only way to extend Existing Code without breaking the backward compatibilty.
But this is just my opinion.
In my java program, I have imported some java packages in one class.
but in there 1 or 2 packages were crossed out.
Why that happened?
How to solve this cross out to make uncrossed?
For the sake of completeness, there is a special case which looks like this in Eclipse:
In the case above there exist three is() methods, which all are statically imported. Hoovering the crossed out method name doesn't give any information, and there isn't a warning marker like there is for #Deprecated classes. In other words, it can be tricky to understand what it means.
In this case, one of the is() methods is #Deprecated, causing the behaviour.
This behaviour was discussed here, a question which was closed as a duplicate.
Those classes are marked as #Deprecated.
This means that the compiler advises not to use them, because they can bring you problems.
A program element annotated #Deprecated is one that programmers are
discouraged from using, typically because it is dangerous, or because
a better alternative exists. Compilers warn when a deprecated program
element is used or overridden in non-deprecated code.
Check the javadoc(s) of the deprecated classes to check which classes to use instead.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What’s “#Override” there for in java?
Since Java 1.5 this annotation was incorporated to the language to be used on methods that overwrite a superclass methods.
Now, what changes in a method that uses this annotation to one that doesn't use it? Is this just convention?
Assuming, obviously, that both be methods that overwrite a method from its superclass...
#Override creates a compile-time check that a method is being overridden.
This is very useful to make sure you do not have a silly signature issue when trying to override
It not only makes the compiler check but also documents the
developer's intention.
if you override a method but don't use it anywhere from the type itself, someone coming to the code later may know the purpose. The annotation explains its purpose.
A good IDE will helpfully flag any method that overrides a method without #Override, so the combination of the two will help ensure that you're doing what you're trying to.
it also improves readability